#include "bits/stdc++.h"
using namespace std;
#define mod 1000000007
#define dom 998244353
#define all(c) begin(c),end(c)
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
template <typename T> bool &chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template <typename T> bool &chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }
#define long long long
#define List vector
#define var auto
#define Count size()
#define Length size()
int dd[] = { 0, 1, 0, -1, 0 }; //→↓←↑

int N;
string T;
bool calc(int size)
{
	var idx = 0;
	var dir = 1;
	for (var s : T)
	{
		if (s == T[idx])
		{
			idx += dir;
			if (idx == size)
			{
				dir = -1;
				idx -= 2;
			}
			else if (idx == -1)
			{
				dir = 1;
				idx += 2;
			}

		}
		else
		{
			return false;
		}
	}
	return true;

}

void solve()
{
	cin >> N;
	cin >> T;

	int ok = N;
	int ng = 1;
	while (ok - ng > 1)
	{
		int mid = (ok + ng) / 2;
		if (calc(mid))
		{
			ok = mid;
		}
		else
		{
			ng = mid;
		}
	}
	cout << (ok) << endl;
}

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	solve();
	return 0;
}
