def CartesianTree(A): n = len(A) P = [-1] * n B = [-1] * n p = -1 for i, a in enumerate(A): while p >= 0 and a < A[B[p]]: j = B[p] p -= 1 if p >= 0 and a < A[B[p]]: P[j] = B[p] else: P[j] = i p += 1 B[p] = i for i in range(p, 0, -1): P[B[i]] = B[i - 1] i = B[0] P[i] = i return P n = int(input()) P = list(map(int, input().split())) for i in range(n): P[i] -= 1 S = input() if S[-1] == "W": if "B" in S: print(-1) else: print(0) exit() idx = P.index(n - 1) P = P[idx:] + P[:idx] ct = CartesianTree([-p for p in P]) child = [[] for _ in range(n)] for i, p in enumerate(ct): if p != i: child[p].append(i) route = [] st = [0] while st: u = st.pop() route.append(u) for v in child[u]: st.append(v) dp = [0] * n for u in route[::-1]: for v in child[u]: if S[P[u]] == "B": dp[u] = max(dp[u], dp[v]) else: dp[u] += dp[v] if S[P[u]] == "B" and dp[u] == 0: dp[u] = 1 print(dp[0])