#include <bits/stdc++.h> 
using namespace std; 
#define ll  long long int
#define mod 1000000007 //10e9+7
#define pb push_back
#define mod1 998244353
// want to become a good coder :p 
 void chalega()
{
    ll a,b;
    cin>>a>>b;
    ll sum1=0,sum2=0;
    ll x=0,y=0;
    while(a>0)
    {
        x=a%10;
        sum1+=x;
        a/=10;
    }
    while(b>0)
    {
        y=b%10;
        sum2+=y;
        b/=10;
    }
    if(sum1>sum2)
    {
      cout<<sum1<<endl;
    }
    else
    {
      cout<<sum2<<endl;
    }
}
  int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    chalega();
}
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pll = pair<ll,ll>;
using pld = pair<ld,ld>;
using vll = vector<ll>;
using vld = vector<ld>;
using vstr = vector<string>;
#define _GLIBCXX_DEBUG
#define rep(j, m) for (ll j = 0; j < (ll)(m); j++)
#define rep2(i, l, n) for (ll i = l; i < (ll)(n); i++)
#define all(v) v.begin(), v.end()
const ld PI = 3.1415926535897932;
const ll MOD = 1000000007;
const ll MOD2 = 998244353;
vll dx = {-1,0,1,0};
vll dy = {0,-1,0,1};
vll Dx = {-1,-1,-1,0,0,1,1,1};
vll Dy = {-1,0,1,-1,1,-1,0,1};
const ll INF = 1000000000000000;

int main() {
    ll N;
    cin >> N;
    string S;
    cin >> S;
    if (S[0] != S[N - 1]) {cout << 1 << endl;}
    else {
        ll flag = 0;
        rep(i,N - 1) {
            if (S[i] != S[0] && S[i + 1] != S[0]) {cout << 2 << endl;flag++;break;}
        }
        if (flag == 0) {cout << -1 << endl;}
    }
}