n = int(input()) s = input().strip() t = input().strip() if s[0] != t[0] or s[-1] != t[-1]: print(-1) exit() D = [0] * n for i in range(n): if s[i] != t[i]: D[i] = 1 count = 0 possible = True for j in range(1, n-1): # j is 0-based, from 1 to n-2 inclusive if D[j] == 1: if j == 1: # Check if S[0] == S[2] if s[0] != s[2]: possible = False break else: # Check if T[j-2] == original S[j] if t[j-2] != s[j]: possible = False break count += 1 if possible: print(count) else: print(-1)