#include<bits/stdc++.h> 
using namespace std;
typedef long long ll;
#define endl '\n';
#define all(x) (x).begin(),(x).end()
template<typename T1,typename T2> bool chmin(T1 &a,T2 b){if(a<=b)return 0; a=b; return 1;}
template<typename T1,typename T2> bool chmax(T1 &a,T2 b){if(a>=b)return 0; a=b; return 1;}
int dx[4]={0,1,0,-1}, dy[4]={1,0,-1,0};
long double eps = 1e-9;
long double pi = acos(-1);



signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    int n;
    cin>>n;
    string s,t;
    cin>>s>>t;
    ll r = 0;
    ll ans = 0;
    for(int i=0;i<n;i++){
        chmax(r,i+1);
        if(s[i] != t[i]){
            while(r<n && s[r] == '0')r++;
            if(r == n){
                cout << -1 << endl;
                return 0;
            }
            ans += r - i;
            s[r] = '0';
            s[i] = t[i];
        }
    }
    cout << ans << endl;

}
#include <bits/stdc++.h>
using namespace std;

int main()
{
  int n;
  cin >> n;
  vector<int> a(n), b(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    b[i] = i + 1;
  }
  sort(begin(a), end(a));
  string ans = "Yes";
  for (int i = 0; i < n; i++) {
    if (a[i] != b[i]) {
      ans = "No";
      break;
    }
  }
  cout << ans << endl;
}
