import java.util.*;

public class LongestEcho {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        try {
            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++) {
                words[i] = sc.next();
                // validate string (only lowercase, 1–10 chars)
                if (!words[i].matches("[a-z]{1,10}")) {
                    System.out.println("Invalid input");
                    return;
                }
            }

            int maxLen = -1;
            int currLen = 1;

            for (int i = 1; i < n; i++) {
                if (!words[i].equals(words[i - 1])) {
                    currLen++;
                } else {
                    maxLen = Math.max(maxLen, currLen);
                    currLen = 1; // restart counting
                }
            }
            maxLen = Math.max(maxLen, currLen);

            if (maxLen < 2) {
                System.out.println(-1);
            } else {
                System.out.println(maxLen);
            }
        } catch (Exception e) {
            System.out.println("Invalid input");
        }
        sc.close();
    }
}