#include <iostream>
#include <algorithm>
using namespace std;

int main()
{
	int N;
	cin >> N;
	int A[N];
	for(int i = 0; i < N; i++){
		cin >> A[i];
	}
	sort(A, A + N);
	for(int i = 1; i <= N; i++){
		if(i != A[i - 1]){
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}
                              ////JAI SHREE RAM////
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
const long long int INF = (long long)1e15;
const long long int mod = 1e9+7;
#define ll long long
#define f(i,a,b) for(int i=a;i<b;i++)
#define pb push_back
#define all(c) c.begin(),c.end()
#define rall(c) c.rbegin(),c.rend()
#define yes cout<<"YES\n"
#define no cout<<"NO\n"
#define sd second
#define ft first
//
bool cmp(const pair<int,int> &a, const pair<int,int> &b)
{
    //return (a.sd>=b.sd);
    return abs(a.ft)+abs(a.sd) < abs(b.ft)+abs(b.sd);
}

void solve()
{
    int n;cin>>n;
    string s;cin>>s;
    if(n>1 && s[0]!=s[n-1]){
        cout<<1<<endl;
        return;
    }
    f(i,1,n-1){
        if(s[i]!=s[0] && s[i+1]!=s[n-1]){
            cout<<2<<endl;
            return;
        }
    }
    cout<<-1<<endl;
}
int main()
{
    ios_base::sync_with_stdio(false); cin.tie(0);cout.tie(0);
    int t=1;
    //cin>>t;

    while(t--)
    {
        solve();
    }
    return 0;
}

