import java.util.*;

public class LongestEcho {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        // Input validation for n
        if (!sc.hasNextInt()) {
            System.out.println("Invalid input");
            return;
        }

        int n = sc.nextInt();
        if (n < 1 || n > 100) {
            System.out.println("Invalid input");
            return;
        }

        String[] words = new String[n];
        for (int i = 0; i < n; i++) {
            if (!sc.hasNext()) {
                System.out.println("Invalid input");
                return;
            }
            String word = sc.next();
            if (!word.matches("[a-z]{1,10}")) { // only lowercase, length 1–10
                System.out.println("Invalid input");
                return;
            }
            words[i] = word;
        }
        sc.close();

        // Find longest continuous echo (no adjacent repeats)
        int maxLen = 1, currentLen = 1;

        for (int i = 1; i < n; i++) {
            if (!words[i].equals(words[i - 1])) {
                currentLen++;
                maxLen = Math.max(maxLen, currentLen);
            } else {
                currentLen = 1; // reset
            }
        }

        // If no valid sequence found, print -1
        if (maxLen <= 1) {
            System.out.println(-1);
        } else {
            System.out.println(maxLen);
        }
    }
}
