import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; public class Sol { public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); int[] types = new int[n]; int[] f = new int[5]; int[] r = new int [5]; Arrays.fill(r , 999999999); int max = 0; for(int types_i=0; types_i < n; types_i++){ types[types_i] = in.nextInt(); } for(int i = 0; i < n; i++) { switch (types[i]){ case 1: f[0]++; break; case 2: f[1]++; break; case 3: f[2]++; break; case 4: f[3]++; break; case 5: f[4]++; break; } } for(int u = 0; u < 5; u++) { if (f[u] > max){ max = f[u]; } } int e = 0; int o = 0; for(int y = o; y < n;y++){ int c = 0; o = 0; for(int x = 0; x < n; x++) { if(types[y] == types [x]){ o++; c++; if(c == max){ r[e] = types[y]; y += o; e++; break; } } } } int min = 0; for(int w = 1; w < 5; w++){ if(r[w-1] < r[w]){ min = r[w-1]; } } System.out.println(min); } }