import sys #input = sys.stdin.readline #input = sys.stdin.buffer.readline #文字列はダメ #sys.setrecursionlimit(1000000) #import bisect #import itertools #import random #from heapq import heapify, heappop, heappush #from collections import defaultdict #from collections import deque #import copy #import math #from functools import lru_cache #@lru_cache(maxsize=None) #MOD = pow(10,9) + 7 #MOD = 998244353 #dx = [1,0,-1,0] #dy = [0,1,0,-1] #一つ目の方法 class RollingHash(): def __init__(self, s, base, mod): self.mod = mod self.pw = pw = [1]*(len(s)+1) l = len(s) self.h = h = [0]*(l+1) v = 0 for i in range(l): h[i+1] = v = (v * base + ord(s[i])) % mod #文字ではなく数字のリストの場合はord不要 v = 1 for i in range(l): pw[i+1] = v = v * base % mod def get(self, l, r): #S[l:r)indexでいうl文字目からr-1文字目 return (self.h[r] - self.h[l] * self.pw[r-l]) % self.mod base1 = 1007; base2 = 2009 mod1 = 1000000007; mod2 = 1000000009 def main(): N = int(input()) A = list(map(int,input().split())) S = list(str(input())) AS = [] for i in range(N-1): if A[i] < A[i+1]: AS.append('<') else: AS.append('>') #print(AS,S) #操作不要 if AS == S: print(0);exit() #ループする場合 if A[N-1] < A[0]: AS.append('<') else: AS.append('>') #print(AS) RHS1 = RollingHash(S,base1,mod1) #N-1文字 RHA1 = RollingHash(AS,base1,mod1) #N文字 RHS2 = RollingHash(S,base1,mod1) #N-1文字 RHA2 = RollingHash(AS,base1,mod1) #N文字 #print(RHS.get(0,N-1)) for i in range(1,N): #[i,N) + [0,i-1) mid = N - i if RHS1.get(0,mid) == RHA1.get(i,N) and RHS1.get(mid,N-1) == RHA1.get(0,i-1): if RHS2.get(0,mid) == RHA2.get(i,N) and RHS2.get(mid,N-1) == RHA2.get(0,i-1): print(i);exit() print(-1) if __name__ == '__main__': main()