import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.Scanner; public class Mugs { int n; final int letters = 20; boolean count[][]; private void setUp() throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); n = Integer.parseInt(br.readLine()); String line = br.readLine(); count = new boolean[letters][n]; count[line.charAt(0) - 'a'][0] = true; for (int i = 1; i < n; ++i) { char c = line.charAt(i); for (int j = 0; j < letters; ++j) { count[j][i] = count[j][i - 1]; } count[c - 'a'][i] = !count[c - 'a'][i]; } } public int solve() throws Exception { setUp(); for (int i = n-1; i > 0; --i) { for (int j = i; j < n; ++j) { boolean seq[] = getInterval(j - i, j); int odd = 0; for (int k = 0; k < letters; ++k) { if (seq[k]) { odd++; } } if ((i + 1) % 2 == 0) { // even if (odd == 0) { //ok return i+1; } } else { // odd if (odd == 1) { //ok return i+1; } } if (odd > 3) { i -= odd-4; break; } } } return 1; } private boolean[] getInterval(int a, int b) { boolean tmp[] = new boolean[letters]; for (int i = 0; i < letters; ++i) { tmp[i] = count[i][b]; if (a > 0) { tmp[i] = (tmp[i] == count[i][a-1] ? false : true); } } return tmp; //ghjahjghsajdjhlfslja } public static void main(String[] args) throws Exception { Mugs m = new Mugs(); System.out.println(m.solve()); } }