I am getting error "Array Index Is Out of Range"

I am making a really simple game in which i want to take 2 string inputs from player via “Input Field” and compare first and last characters of both strings and if first alphabet of 2nd word is not equal to first alphabet then change the scene.
please please please help me with this
Thank You

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;

public class Input1 : MonoBehaviour
{
    public InputField word1;
    public InputField word2;

    void FixedUpdate()
        {
            string p1word = word1.text;          //taking value from input field to string
            string p2word = word2.text;
            char p1firstltr = p1word[0];           //first characters of p1word
            char p2firstltr = p2word[0];
            char p1lastltr = p1word[p1word.Length - 1];//last characters of p1word
            char p2lastltr = p2word[p2word.Length - 1];

            if (p2firstltr != p1lastltr)    //comparing both characters
            {
                SceneManager.LoadScene(4);  //change scene
            }

            else if (p1firstltr != p2lastltr)
            {
            SceneManager.LoadScene(5);
            }
        }
}

Your logic is in fixedupate which is called every physics tick. That could be multiple times per frame or not at all. So your code is being executed before anything is entered into the inputfields

What you should do is add a button, name it check result or something and then in the buttons onclick event, call a method containing your logic.