// Author: Adrian Kuegel
// Complexity: O(n)
// Algorithm: Scanline

#include <iostream>
#include <fstream>
#include <string>
#include <algorithm>
#include <ctype.h>
#include <assert.h>
using namespace std;

#define in cin

int main() {
	string text;
	int m;
//	ifstream in("broken.in");
	while(in >> m && m > 0) {
		// skip newline
		getline(in, text);
		// read text
		getline(in, text);
		assert(text.size() <= 1000000);
		int cnt[128] = {0};
		int ndiff = 0;
		int s = 0;
		int best = 0;
		for (int i=0; i<(int)text.size(); ++i) {
			assert(text[i] >= 0 && text[i] < 128 && !iscntrl(text[i]));
			if (++cnt[text[i]] == 1) {
				if (++ndiff > m) {
					while(--cnt[text[s++]] > 0);
					--ndiff;
				}
			}
			best = max(best, i-s+1);
		}
		cout << best << endl;
	}
	assert(m == 0);
	return 0;
}
