def Z_algorithm(S): N=len(S) arr = [0]*N arr[0] = N i,j = 1,0 while i') n -= 1 t = ''.join(t) l = Z_algorithm(s + t)[n:] ans = -1 #print(''.join(list(s + t)[n:])) #print(l) for i in range(n + 1): if l[i] >= n: ans = i break return ans n = int(input()) a = list(map(int,input().split())) s = input() print(solve(n, a, s))