/* Created By::Shashwat Singh
 *             (shashwa_t)
 * 
 * Alwayz look for edge cases(n=1 or 1111 or similar mutiple values).
 * Look for integer overflow.(>=10^6);
 * Look for out of bounds(array);
*/
# include<bits/stdc++.h>
# define ll long long
# define pb push_back
# define endl "\n"
# define mod 1000000007ll
# define pi  3.1415926535897932384626
using namespace std;
void solve()
{
  long long n,x=-1; cin>>n;
  string s,t; cin>>s>>t;
  set<long long>ind;
  for(int i=0;i<n;i++)
   {
     if(s[i]=='1')
      ind.insert(i);
   }
   long long ans=0;
   for(int i=0;i<n;i++)
   {
     if(i<=x)
     {
       s[i]='0';
       if(s[i]!=t[i])
       {
         auto it=ind.upper_bound(x);
         if(it!=ind.end())
         {
           x=*it;
           ans+=(x-i);
         }
           else
          {
            cout<<-1; return;
          }
       }
     }
     else if(s[i]!=t[i])
     {
       auto it=ind.upper_bound(i);
       if(it!=ind.end())
       {
         x=*it;
         ans+=(x-i);
       }
       else
       {
         cout<<-1; return;
       }
     }
   }
   cout<<ans;
}
int main()
{   
 # ifndef ONLINE_JUDGE
   freopen("input1.txt","r",stdin);
   freopen("output1.txt","w",stdout);
 # endif
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    
    solve();
     cout<<endl; 

    return 0;
}
#include <bits/stdc++.h>
 
#define pb push_back
#define db1(x) cout << #x << " = " << x << endl
#define db2(x, y) cout << #x << " = " << x << ", " << #y << " = " << y << endl
#define paging cout << "-----------------------" << endl
 
using namespace std;
void localFileInput() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
#endif
}
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const ll mod = 998244353;
const int INF = 0x3f3f3f3f;
const int N = 1e5+10;
int a, b, c, d;
void sol() {
    cin >> a >> b >> c >> d;
    a = a * d - b * c;
    cout << a << endl;
}
int main()
{
    // localFileInput();
    // int _; scanf("%d", &_); while(_ --)
    sol();
    return 0;
}