import sys sys.setrecursionlimit(200005) # sys.set_int_max_str_digits(200005) int1 = lambda x: int(x)-1 pDB = lambda *x: print(*x, end="\n", file=sys.stderr) p2D = lambda x: print(*x, sep="\n", end="\n\n", file=sys.stderr) def II(): return int(sys.stdin.readline()) def LI(): return list(map(int, sys.stdin.readline().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] def LI1(): return list(map(int1, sys.stdin.readline().split())) def LLI1(rows_number): return [LI1() for _ in range(rows_number)] def SI(): return sys.stdin.readline().rstrip() dij = [(0, 1), (-1, 0), (0, -1), (1, 0)] # dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)] # inf = -1-(-1 << 31) inf = -1-(-1 << 62) # md = 10**9+7 md = 998244353 from random import randrange BASE = randrange(128, 256) MOD = 2147483629 class RollingHash: def __init__(self, target): self.N = len(target) self.table = [0] self.power = [1] for c in target: self.table += [(self.table[-1]*BASE)%MOD+c] self.power += [self.power[-1]*BASE%MOD] def hashing(self, s): h = 0 for c in s: h = h*BASE%MOD+c return h%MOD def hash_lr(self, l, r): return (self.table[r]-self.table[l]*self.power[r-l]%MOD)%MOD def find(self, s, start=0): h = self.hashing(s) for i in range(start, self.N-len(s)+1): if self.hash_lr(i, i+len(s)) == h: return i return -1 def find_all(self, s): res = [] h = self.hashing(s) for i in range(self.N-len(s)+1): if self.hash_lr(i, i+len(s)) == h: res.append(i) return res # def todd(s): # # print(s) # dd=[] # r=n-1 # while not s[r]:r-=1 # p=r # for i in range(r+1): # if s[i]: # dd.append((i-p)%n) # p=i # return dd n=II() aa=LI() s=[c==">" for c in SI()] s1=sum(s) t=[aa[i]>aa[i+1] for i in range(n-1)] t.append(aa[n-1]>aa[0]) t1=sum(t) if s1==t1: s.append(False) elif s1+1==t1: s.append(True) else: print(-1) exit() # sd=todd(s) # td=todd(t) # print(s) # print(t) # print(sd) # print(td) rh=RollingHash(t+t) hs=rh.hashing(s) for i in range(n): if rh.hash_lr(i,i+n)==hs: print(i) exit() print(-1)