#!/usr/bin/env PyPy3 from collections import Counter, defaultdict, deque import itertools import re import math from functools import reduce import operator import bisect from heapq import * import functools mod=998244353 import sys input=sys.stdin.readline n = int(input()) s = list(input().rstrip()) t = list(input().rstrip()) if s[0] != t[0] or s[-1] != t[-1]: print(-1) exit() ans = 0 fl = 0 j = 0 li = [0] * n fll = [0] * n for i in range(1,n-1): if li[i]: fl = 1 - fl fll[i] = fl if (fl == 0 and s[i] != t[i]) or (fl == 1 and s[i] == t[i]): j = max(j,i + 1) while j < n and ((fll[j-2] == 0 and s[j-2] != s[j]) or (fll[j-2] == 1 and s[j-2] == s[j])): j += 1 if j == n: print(-1) break li[j] += 1 ans += j - i j += 1 fl = 1 - fl #print(fl,i) fll[i] = fl else: print(ans)