//#define NDEBUG
#include <cstddef>
#include <cstdint>
#include <vector>

using i8 = ::std::int_least8_t;
using i32 = ::std::int_least32_t;
using i64 = ::std::int_least64_t;
using u8 = ::std::uint_least8_t;
using u32 = ::std::uint_least32_t;
using u64 = ::std::uint_least64_t;
using isize = ::std::ptrdiff_t;
using usize = ::std::size_t;

template <class T = usize> class rep {
	const T f, l;

public:
	class itr {
		friend rep;
		T i;
		constexpr itr(T x) noexcept : i(x) {}

	public:
		void operator++() noexcept { ++i; }
		constexpr T operator*() const noexcept { return i; }
		constexpr bool operator!=(const itr x) const noexcept { return i != x.i; }
	};
	constexpr rep(const T first, const T last) noexcept : f(first), l(last) {}
	constexpr itr begin() const noexcept { return itr(f); }
	constexpr itr end() const noexcept { return itr(l); }
};
template <class T = usize> class revrep {
	const T f, l;

public:
	class itr {
		friend revrep;
		T i;
		constexpr itr(T x) noexcept : i(x) {}

	public:
		void operator++() noexcept { --i; }
		constexpr T operator*() const noexcept { return i; }
		constexpr bool operator!=(const itr x) const noexcept { return i != x.i; }
	};
	constexpr revrep(const T first, const T last) noexcept : f(first), l(last) {}
	constexpr itr begin() const noexcept { return itr(l - 1); }
	constexpr itr end() const noexcept { return itr(f - 1); }
};
template <class T> bool amax(T &a, const T &b) {
	return a <= b ? (a = b, 1) : 0;
}
template <class T> bool amin(T &a, const T &b) {
	return b <= a ? (a = b, 1) : 0;
}
template <class T> bool asmax(T &a, const T &b) {
	return b <= a ? 0 : (a = b, 1);
}
template <class T> bool asmin(T &a, const T &b) {
	return a <= b ? 0 : (a = b, 1);
}
template <class T> using vec_alias = ::std::vector<T>;
template <class T> auto md_vec(usize n, const T &value) {
	return ::std::vector<T>(n, value);
}
template <class... Args> auto md_vec(usize n, Args... args) {
	return ::std::vector<decltype(md_vec(args...))>(n, md_vec(args...));
}
template <class T> const T &as_const(const T &v) noexcept { return v; }
template <class T> constexpr T difference(const T &a, const T &b) {
	return a <= b ? b - a : a - b;
}

#include <algorithm>
#include <iostream>
#include <utility>
#include<stack>
#include<string>
#include<set>

template<u64 MOD,u64 BASE>
class roriha {
	std::vector<u64> suffix, pow;
public:
	roriha(const std::vector<u64> &s) :suffix(s.size()+1), pow(s.size()+1) {
		const usize n = s.size();
		u64 t = 0;
		suffix[n] = t;
		for (usize i = n;i--;) {
			t = (t*BASE + s[i]) % MOD;
			suffix[i] = t;
		}
		t = 1;
		for (usize i = 0;i <= n;++i) {
			pow[i] = t;
			t = (t*BASE) % MOD;
		}
	}

	u64 hash(const usize l, const usize r)const {
		const u64 lh = suffix[l];
		const u64 rh = (suffix[r] * pow[r - l]) % MOD;
		return lh < rh ? lh + MOD - rh : lh - rh;
	}
};

int main() {
	static constexpr u64 MOD0=1000000007, BASE0=5, MOD1 = 1000000009, BASE1=13;
	usize n;
	std::cin >> n;
	std::string t;
	std::cin >> t;
	std::vector<u64> ft(n);
	for (const auto i : rep<>(0, n)) {
		ft[i] = t[i] - 'a';
	}
	auto rt = ft;
	std::reverse(rt.begin(), rt.end());

	const roriha<MOD0, BASE0> fh0(ft), rh0(rt);
	const roriha<MOD1, BASE1> fh1(ft), rh1(rt);

	for (const auto s : rep<>(2, n + 1)) {
		const u64 f0 = fh0.hash(0, s), r0 = rh0.hash(n - s, n);
		const u64 f1 = fh1.hash(0, s), r1 = rh1.hash(n - s, n);

		bool f = false;
		for (usize i = 0;(i+s) <= n;i += 2 * s - 2) {
			const u64 h0 = fh0.hash(i, i + s);
			const u64 h1 = fh1.hash(i, i + s);
			if (h0 != f0 || h1 != f1) {
				f = true;
				break;
			}
		}
		if (f) {
			continue;
		}
		f = false;
		for (usize i = s - 1;(i + s) <= n;i += 2 * s - 2) {
			const u64 h0 = fh0.hash(i, i + s);
			const u64 h1 = fh1.hash(i, i + s);
			if (h0 != r0 || h1 != r1) {
				f = true;
				break;
			}
		}
		if (f) {
			continue;
		}

		const usize last_s = (n - 1) % (s - 1) + 1;
		const usize last_i = n - last_s;

		if (last_i / (s - 1) % 2 == 0) {
			if (false
				|| fh0.hash(0, last_s) != fh0.hash(last_i, n)
				|| fh1.hash(0, last_s) != fh1.hash(last_i, n)) {
				continue;
			}
		}
		else {
			if (false
				|| rh0.hash(n - s, n - (s - last_s)) != fh0.hash(last_i, n)
				|| rh1.hash(n - s, n - (s - last_s)) != fh1.hash(last_i, n)) {
				continue;
			}
		}

		std::cout << s << std::endl;
		return 0;
	}

	return 0;
}



Measured memory_bytes: 82052