#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <array>
#include <random>
#include <cmath>
#include <chrono>
#include <list>
#include <ctime>
#include <sstream>
#include <queue>
#include <climits>
#include <stack>
#include <random>
#include <bitset>
#include <numeric>
#include <cassert>
using namespace std;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;
#define rep(x, b, e) for(int x=(b); x<(e); ++x)
#define trav(a, x) for(auto& a : x)
#define ford(x, b, e) for(int x=((int)(b))-1; x>=(e); --x)
#define all(c) c.begin(),c.end()
#define sz(x) ((int)((x).size()))
#define pb push_back
#define st first
#define nd second
#define mp(x,y) make_pair(x,y)
typedef short int sint;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); // use rng() to get unsigned int
// mt19937_64 for random long longs

void solve() {
	string x;
	int n;
	cin >> n;
	cin >> x;
	if (x[0] != x.back()) {
		cout << 1 << endl;
		return;
	}
	// int n = sz(x);
	rep(i, 1, n-2) {
		if (x[i] != x[0] && x[i + 1] != x[0]) {
			cout << 2 << endl;
			return;
		}
	}
	cout << -1 << endl;
}

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
	int t;
	// cin >> t;
	t = 1;
	while (t--) {
		solve();
	}
}
#include <bits/stdc++.h>
using namespace std;
char s[200200];
int main(void) {
    int n; scanf("%d%s",&n,s);
    int top=0;
    for (int i=0;i<n;i++) {
        if (top < 2) {
            s[top++]=s[i];
        } else {
            if (s[i] == 'x') {
                if (s[top-2] == 'f' && s[top-1] == 'o') top -= 2;
                else s[top++]=s[i];
            } else s[top++]=s[i];
        }
    }
    printf("%d\n",top);
    return 0;
}
