#include void Z_algorithm(char S[], int Z[]) { int i, j, k, l; for (l = 0; S[l] != 0; l++); Z[0] = l; for (i = 1, j = 0; i < l; i++) { for (; i + j < l && S[i+j] == S[j]; j++); Z[i] = j; if (j == 0) continue; for (k = 1; k < j && k + Z[k] < j; k++) Z[i+k] = Z[k]; i += k - 1; j -= k; } } int main() { int i, N, A[300001]; char S[1000000]; scanf("%d", &N); for (i = 1; i <= N; i++) scanf("%d", &(A[i])); scanf("%s", S); for (i = 1; i < N; i++) { if (A[i] < A[i+1]) S[N+i-2] = '<'; else S[N+i-2] = '>'; } if (A[N] < A[1]) S[N*2-2] = '<'; else S[N*2-2] = '>'; for (i = 1; i < N; i++) S[N*2+i-2] = S[N+i-2]; S[N*3-2] = 0; int Z[1000000]; Z_algorithm(S, Z); for (i = 0; i < N; i++) if (Z[N+i-1] >= N - 1) break; if (i < N) printf("%d\n", i); else printf("-1\n"); fflush(stdout); return 0; }