n = int(input()) s = list(input().strip()) t = list(input().strip()) operations = 0 for i in range(n - 2): if s[i] != s[i + 2]: continue if s[i + 1] == t[i + 1]: continue # Perform the flip s[i + 1] = 'A' if s[i + 1] == 'B' else 'B' operations += 1 if s == t: print(operations) else: print(-1)