#include #include #include struct SUBSTR { int poc['z'-'a'+1]; int operator()(const SUBSTR &s2) const { int i; int ret=0; for (i = 0; i < 'z'-'a'+1; i++) { ret=33*ret+s2.poc[i]; } return ret; } bool operator==(const SUBSTR &s2) const { int i; for (i = 0; i < 'z'-'a'+1; i++) { if (poc[i] != s2.poc[i]) { return 0; } } return 1; } }; int k; static char str[100010]; static char ps[100010]; static int vzd[100010]; int n; hash_set s1; int main() { int dlz; int i,j; SUBSTR tmp; while (1) { s1.clear(); gets(str); sscanf(str, " %d", &k); if (k == 0) { break; } gets(str); j=0; for (i = 0; str[i] != 0; i++) { if (str[i] <= 'Z' && str[i] >= 'A') { str[i]=str[i]-'A'+'a'; } if (str[i] <= 'z' && str[i] >= 'a') { ps[j]=str[i]; vzd[j]=i; j++; } } dlz=i; ps[j]=0; n=j; if (n <= k) { printf("%d\n", dlz); continue; } for (i=0; i <'z'-'a'+1; i++) { tmp.poc[i]=0; } for (i = 0; i < k; i++) { tmp.poc[ps[i]-'a']++; } s1.insert(tmp); int nas=0; for (i = k; i < j; i++) { tmp.poc[ps[i]-'a']++; tmp.poc[ps[i-k]-'a']--; if (s1.find(tmp) != s1.end()) { printf("%d\n", vzd[i]); nas=1; break; } else { s1.insert(tmp); } } if (nas == 0) { printf("%d\n", dlz); } } return 0; }