#pragma GCC optimize ("O2")
#pragma GCC target ("avx2")
#include<bits/stdc++.h>
//#include<atcoder/all>
//using namespace atcoder;

using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please


int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);


	int N;
	cin >> N;
	string S, T;
	cin >> S >> T;


	ll kotae = 0;
	queue<int> q;
	int jogai = -1;
	rep(i, N) {
		if (jogai >= 0 && S[i] == '1') {
			S[i] = '0';
			kotae += i - jogai;
			jogai = -1;
		}

		if (T[i] == '1') q.push(i);

		if (S[i] == '1') {
			if (q.size()) {
				int tmp = q.front();
				q.pop();
				kotae += i - tmp;
			}
			else {
				jogai = i;
			}
		}
	}

	if (jogai == -1 && q.empty()) {
		co(kotae);
	}
	else co(-1);

	Would you please return 0;
}
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <algorithm>
#include <math.h>
#include <iomanip>
#include <sstream>
#define INF 1000000009
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using p = pair<int, int>;
 
int h,w;
 
ll calc(vector<vector<int>> m,int a, int b, int x, int y){
    
    if(a<0||b<0) return 0;
    if(x==h-1&&y==w-1){
        if(m[x][y]==1&&a==0&&b==0) return 1;
        else if(m[x][y]==0&&a==0&&b==1) return 1;
        else return 0; 
    }
    else{
        if(m[x][y]==0){
            m[x][y] = 1;
            vector<vector<int>> m1 = m;
            if(x==h-1){
                m1[x][y+1] = 1;
                return calc(m,a,b-1,0,y+1) + calc(m1,a-1,b,0,y+1);
            }else{
                vector<vector<int>> m2 = m;
                m1[x][y+1] = 1;
                m2[x+1][y] = 1;
                return calc(m,a,b-1,x+1,y) + calc(m1,a-1,b,x+1,y) + calc(m2,a-1,b,x+1,y);
            }
        }else{
            if(x==h-1) return calc(m,a,b,0,y+1);
            else return calc(m,a,b,x+1,y);
        }
    }
}
 
int main() {
    
    ll ans;
    int a,b;
    ans = 0;
 
    cin >> h>>w>>a>>b;
    vector<vector<int>> m(h+1,vector<int>(w+1,0));
    
    ans = calc(m,a,b,0,0);
    cout << ans << endl;
    return 0;
}