Morse index theorem