#line 1 "Contests/AtCoder_agc054/agc054_a/main.cpp"
using namespace std;
#line 2 "library/bits/stdc++.h"

// C
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
#line 3 "Contests/AtCoder_agc054/agc054_a/main.cpp"

// add your library with double quotation #include"" here.
// #include "atcoder/all"
// using namespace atcoder;

// define your macros here.
#define REP(a,b) for(long long a = 0;a < b;++a)

#define int long long
void solve(){
    // write your solution here.
    int n;
    cin >> n;
    string s;
    cin >> s;
    if(s[0] != s.back()){
        cout << 1 << endl;
        return;
    }
    for(int i = 1;i < s.length()-1;++i){
        if(s[i] != s[0] and s[i+1] != s.back()){
            cout << 2 << endl;
            return;
        }
    }
    cout << -1 << endl;
}
#undef int

// generated by oj-template v4.7.2 (https://github.com/online-judge-tools/template-generator)
int main() {
    // Fasterize input/output script
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(100);
    // scanf/printf user should delete this fasterize input/output script

    int t = 1;
    //cin >> t; // comment out if solving multi testcase
    for(int testCase = 1;testCase <= t;++testCase){
        solve();
    }
    return 0;
}

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

int main(void)
{
  long N;
  string s;
  deque<char> deq;
  
  cin >> N;
  cin >> s;
  
  for (long i = 0; i < N; i++)
  {
    deq.push_back(s.at(i));
    
    if (deq.size() >= 3 && deq.at(deq.size()-3) == 'f' && deq.at(deq.size()-2) == 'o' && deq.back() == 'x')
    {
      deq.pop_back();
      deq.pop_back();
      deq.pop_back();
    }
  }
  
  cout << deq.size() << endl;
}