n=int(input()) s=[*input()] t=[*input()] S=s[:] T=t[:] a=[] ans=0 for i in range(n-2)[::2]: if s[i]==s[i+2]: if s[i+1]!=t[i+1]: s[i+1]=t[i+1] ans+=1 for i in range(1,n-2)[::2]: if s[i]==s[i+2]: if s[i+1]!=t[i+1]: s[i+1]=t[i+1] ans+=1 if s==t:a.append(ans) ans=0 s=S[:] t=T[:] for i in range(1,n-2)[::2]: if s[i]==s[i+2]: if s[i+1]!=t[i+1]: s[i+1]=t[i+1] ans+=1 for i in range(n-2)[::2]: if s[i]==s[i+2]: if s[i+1]!=t[i+1]: s[i+1]=t[i+1] ans+=1 if s==t:a.append(ans) if len(a)==0:print(-1) else:print(min(a))