int n,m,x,y,ans,cnt,flag,f[37][1000015],h[37][1000015],e[100005];
structtwo{ int num[47],p; }g[1000015];
voidbroke(int x,int i) { int cnt = 0; while(x > 0) { f[++cnt][i] = x & 1; x >>= 1; } }
voidinit() { n = read(); m = read(); for(int i = 1; i <= n; i++) { y = x; x = read(); e[i] = x; if(x != y && x > 1) flag = 1; broke(x,i); } }
voidmake1() { for(int i = 1; i <= m; i++) for(int j = 1; j <= n; j++) f[i][j] = f[i][j - 1] + f[i][j]; }
intmysort(two a,two b) { int k = 1; while(a.num[k] == b.num[k] && k <= m) k++; if(k <= m) return a.num[k] < b.num[k]; return a.p < b.p; }
voidmake2() { for(int i = 2; i <= m; i++) for(int j = 1; j <= n; j++) g[j].num[i] = f[i][j] - f[i - 1][j],g[j].p = j; sort(g, g + n + 1,mysort); }
boolcmp(int a,int b) { for(int i = 1; i <= m; i++) if(g[a].num[i] != g[b].num[i]) returnfalse; returntrue; }
voidfind() { ans = 0; int head = 0; while(head < n) { int k = head; while(cmp(k + 1,head) && k < n) k++; if(k <= n) ans = max(ans,g[k].p - g[head].p); head = k + 1; } }
intmain() { init(); if(flag == 0) { int k = 0; while(e[k + 1] == 0 && k < n) k++; printf("%d\n",k); return0; } make1(); make2(); find(); printf("%d\n",ans); return0; }