N = int(input()) S = input() T = input() S_ = []; T_ = [] if not (S[0] == T[0] and S[-1] == T[-1]): print(-1) exit() for i in range(N): s = 1 if S[i] == 'A' else 0 t = 1 if T[i] == 'A' else 0 S_.append(s); T_.append(t) S_diff = []; T_diff = [] for i in range(N - 1): s = S_[i] ^ S_[i + 1] t = T_[i] ^ T_[i + 1] S_diff.append(s); T_diff.append(t) S_inv = []; T_inv = [] for i in range(N - 1): if i & 1: S_diff[i] = 1 - S_diff[i] T_diff[i] = 1 - T_diff[i] if S_diff[i] == 1: S_inv.append(i) if T_diff[i] == 1: T_inv.append(i) if len(S_inv) != len(T_inv): print(-1) exit() print(sum([abs(s - t) for s, t in zip(S_inv, T_inv)])) exit()