#include using namespace std; typedef long long int ll; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; string s, t; cin >> s >> t; if (s[0] != t[0]) { cout << -1 << endl; return 0; } vector a, b; for (int i = 0; i + 1 < n; ++i) { int diff = abs(s[i] - s[i + 1]); if (i % 2) diff ^= 1; if (diff) a.push_back(i); } for (int i = 0; i + 1 < n; ++i) { int diff = abs(t[i] - t[i + 1]); if (i % 2) diff ^= 1; if (diff) b.push_back(i); } if (a.size() != b.size()) { cout << -1 << endl; return 0; } ll res = 0; for (int i = 0; i < a.size(); ++i) { res += abs(a[i] - b[i]); } cout << res << endl; }