#include <bits/stdc++.h>
using namespace std;

int main() {
    int N;
    string S;
    cin >> N >> S;
    if(S[0] != S[N-1]) {
        cout << 1 << endl;
    }
    else {
        bool flag = false;
        for(int i = 1; i < N-2; i++) {
            if(S[0] != S[i] && S[N-1] != S[i+1]) {
                flag = true;
            }
        }
        if(flag) {
            cout << 2 << endl;
        }
        else {
            cout << -1 << endl;
        }
    }
}

#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define f first 
#define s second 
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
const ll inf=1e18+5;
const int mod=1e9+7;
int main(){
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);
    ll b,c;
    cin>>b>>c;
    ll l1=b-c/2, r1=b+(c-2)/2, l2=-b-(c-1)/2, r2=-b+(c-1)/2;
    if(r1<l2 || r2<l1){
        cout<<r1-l1+1+r2-l2+1<<endl;
    }
    else{
        cout<<max(r1,r2)-min(l1,l2)+1<<endl;
    }
}