N = int(input()) A = list(map(int,input().split())) S = input() T = [] for i in range(N-1): if A[i] < A[i+1]: T.append('<') else: T.append(">") if A[-1] < A[0]: T.append("<") else: T.append(">") T = "".join(T) T = S + T + T n = len(T) Z = [0] * n Z[0] = n i = 1 j = 0 while i < n: while i + j < n and T[i+j] == T[j]: j += 1 Z[i] = j if j == 0: i += 1 continue k = 1 while k < j and k + Z[k] < j: Z[i+k] = Z[k] k += 1 i += k j -= k import sys for i in range(N-1,n): if Z[i] >= N-1: print(i-N+1) exit() print(-1)