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 v = 1 for i in range(l): pw[i+1] = v = v * base % mod def get(self, l, r): return (self.h[r] - self.h[l] * self.pw[r-l]) % self.mod base = 37; mod = 10**9 + 9 N = int(input()) A = list(map(int, input().split())) A = A+[A[0]] S = input() L = [] for i in range(N): if A[i]') L = ''.join(map(str, L))*2 SRH = RollingHash(S,base,mod) LRH = RollingHash(L,base,mod) m = SRH.get(0,len(S)) for i in range(N): if m == LRH.get(i,len(S)+i): print(i) exit() print(-1)