#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#define int long long
using namespace std;
inline int read()
{
	int x=0;
	bool flag=1;
	char c=getchar();
	while(c<'0'||c>'9')
	{
		if(c=='-')
			flag=0;
		c=getchar();
	}
	while(c>='0'&&c<='9')
	{
		x=(x<<1)+(x<<3)+c-'0';
		c=getchar();
	}
	return (flag?x:~(x-1));
}
int n;
string s;
signed main()
{
	cin>>n;
	cin>>s;
	if(s[0]!=s[s.size()-1])
	{
		puts("1");
		return 0; 
	}
	for(int i=1;i+2<s.size();i++)
	{
		if(s[0]!=s[i]&&s[i+1]!=s[s.size()-1])
		{
			puts("2");
			return 0;
		}
	}
	puts("-1");
	return 0;
}

#include <bits/stdc++.h>

using namespace std;

#define ar array
#define ll long long

const int MAX_N = 1e5 + 1;
const ll MOD = 1e9 + 7;
const ll INF = 1e9;

int findMaxGCD(int arr[], int n)
{
    // Calculating MAX in array
    int high = 0;
    for (int i = 0; i < n; i++)
        high = max(high, arr[i]);
 
    // Maintaining count array
    int count[high + 1] = {0};
    for (int i = 0; i < n; i++)
        count[arr[i]]++;
 
    // Variable to store the
    // multiples of a number
    int counter = 0;
 
    // Iterating from MAX to 1
    // GCD is always between
    // MAX and 1. The first
    // GCD found will be the
    // highest as we are
    // decrementing the potential
    // GCD
    for (int i = high; i >= 1; i--)
    {
        int j = i;
       counter = 0;
   
        // Iterating from current
        // potential GCD
        // till it is less than
        // MAX
        while (j <= high)
        {
            // A multiple found
 
            if(count[j] >=2)
               return j;
 
           else if (count[j] == 1)        
                counter++;        
 
            // Incrementing potential
            // GCD by itself
            // To check i, 2i, 3i....
            j += i;
 
            // 2 multiples found,
            // max GCD found
            if (counter == 2)        
                return i;
        }
    }
}

void solve() {
    int a, b; cin >> a >> b;
    int n = b - a + 1;
    int arr[n];
    for (int i = a, j = 0; i <= b; i++, j++) arr[j] = i;
    cout << findMaxGCD(arr, n) << "\n";
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int tc = 1;
    // cin >> tc;
    for (int t = 1; t <= tc; t++) {
        // cout << "Case #" << t << ": ";
        solve();
    }
}