n = int(input()) s = list(input()) t = list(input()) diff_positions = [] for i in range(n): if s[i] != t[i]: diff_positions.append(i) count = 0 possible = True for i in diff_positions: if i < 1 or i >= n-1: possible = False break if s[i-1] != s[i+1]: possible = False break # Perform the operation s[i] = 'B' if s[i] == 'A' else 'A' count += 1 if possible and s == t: print(count) else: print(-1)