#include #include #include #include #include using namespace std; using u64 = unsigned long long; #define rep(i,n) for(int i=0; i<(int)(n); i++) using modint = atcoder::static_modint<998244353>; int main(){ int N; cin >> N; vector A(N); rep(i,N) cin >> A[i]; string S; cin >> S; rep(i,N-1) A.push_back(A[i]); string G; rep(i,A.size()-1){ if(A[i] < A[i+1]) G.push_back('<'); else G.push_back('>'); } auto Q = atcoder::z_algorithm(S+G); vector goals; rep(i,N) if(Q[N-1+i] >= N-1) goals.push_back(i); if(goals.empty()){ cout << "-1\n"; return 0; } cout << goals[0] << endl; return 0; } struct ios_do_not_sync{ ios_do_not_sync(){ std::ios::sync_with_stdio(false); std::cin.tie(nullptr); } } ios_do_not_sync_instance;