import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        try {
            // Read number of strings
            if (!sc.hasNextInt()) {
                System.out.println("Invalid input");
                return;
            }
            int n = sc.nextInt();
            sc.nextLine(); // consume newline

            if (n < 1 || n > 100) {
                System.out.println("Invalid input");
                return;
            }

            // Read words
            if (!sc.hasNextLine()) {
                System.out.println("Invalid input");
                return;
            }
            String[] words = sc.nextLine().trim().split("\\s+");

            if (words.length != n) {
                System.out.println("Invalid input");
                return;
            }

            // Validate constraints: lowercase letters, length 1–10
            for (String w : words) {
                if (!w.matches("[a-z]{1,10}")) {
                    System.out.println("Invalid input");
                    return;
                }
            }

            int maxLen = -1;
            int currentLen = 1;

            for (int i = 1; i < n; i++) {
                if (!words[i].equals(words[i - 1])) {
                    currentLen++;
                } else {
                    maxLen = Math.max(maxLen, currentLen);
                    currentLen = 1; // restart count
                }
            }

            // Update for last sequence
            maxLen = Math.max(maxLen, currentLen);

            // If no valid sequence found
            if (maxLen < 2) {
                System.out.println(-1);
            } else {
                System.out.println(maxLen);
            }

        } catch (Exception e) {
            System.out.println("Invalid input");
        }
    }
}