n = int(input()) s = list(input()) t = list(input()) count = 0 for i in range(n - 2): # Check positions from 1 to N-2 (0-based 0 to N-3) if s[i] == s[i + 2]: if s[i + 1] != t[i + 1]: # Flip the character s[i + 1] = 'A' if s[i + 1] == 'B' else 'B' count += 1 # Check the remaining positions (N-2 to N-1) might need to check again # After processing, check if s equals t if s == t: print(count) else: print(-1)