import java.util.Scanner;

public class AlabastaEcho {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        try {
            // Read number of words
            int n = sc.nextInt();
            if (n < 1 || n > 100) {
                System.out.println("Invalid input");
                return;
            }

            // Read words
            String[] words = new String[n]; // ✅ using 'new' keyword
            for (int i = 0; i < n; i++) {
                if (!sc.hasNext()) {
                    System.out.println("Invalid input");
                    return;
                }
                words[i] = sc.next();
                if (!words[i].matches("[a-z]{1,10}")) {
                    System.out.println("Invalid input");
                    return;
                }
            }

            // Edge case: if only one word, longest echo is 1
            if (n == 1) {
                System.out.println(1);
                return;
            }

            // Find longest sequence without consecutive repetition
            int maxLen = 1;
            int currentLen = 1;

            for (int i = 1; i < n; i++) {
                if (!words[i].equals(words[i - 1])) {
                    currentLen++;
                } else {
                    currentLen = 1;
                }
                maxLen = Math.max(maxLen, currentLen);
            }

            System.out.println(maxLen > 0 ? maxLen : -1);

        } catch (Exception e) {
            System.out.println("Invalid input");
        }
    }
}
