#include #include #include #include #include #include using namespace std; using i32 = int32_t; using u32 = uint32_t; using i64 = int64_t; using u64 = uint64_t; #define rep(i,n) for(int i=0; i<(int)(n); i++) const i64 INF = 1001001001001001001; using modint = atcoder::static_modint<1000000007>; int main(){ int N; cin >> N; string S; cin >> S; vector Sx(N-1); rep(i,N-1) Sx[i] = (S[i] == S[i+1]) ? 0 : 1; string T; cin >> T; vector Tx(N-1); rep(i,N-1) Tx[i] = (T[i] == T[i+1]) ? 0 : 1; if(S[0] != T[0]){ cout << "-1n"; return 0; } N--; rep(i,N) if(i%2==0) Sx[i] ^= 1; rep(i,N) if(i%2==0) Tx[i] ^= 1; vector Si; rep(i,N) if(Sx[i] == 0) Si.push_back(i); vector Ti; rep(i,N) if(Tx[i] == 0) Ti.push_back(i); if(Si.size() != Ti.size()){ cout << "-1\n"; return 0; } i64 ans = 0; rep(i,Si.size()) ans += abs(Si[i] - Ti[i]); cout << ans << '\n'; return 0; } struct ios_do_not_sync{ ios_do_not_sync(){ std::ios::sync_with_stdio(false); std::cin.tie(nullptr); } } ios_do_not_sync_instance;