N = int(input()) S = [ord(a) - 65 for a in input()] T = [ord(a) - 65 for a in input()] if S[0] != T[0] or S[-1] != T[-1]: print(-1) exit() before, flip, ans = 0, 0, 0 for i in range(N - 1): xor = S[i] ^ T[i] next_xor = S[i+1] ^ T[i+1] r_before = before ^ xor ^ (flip & 1) ^ (S[i-1] ^ S[i+1]) if flip else 0 next_flip = max(0, flip + r_before - 1) if (next_flip ^ next_xor) % 2: next_flip += 1 before = r_before ^ 1 if flip and next_flip else 0 flip = next_flip ans += flip print(-1 if flip else ans)