#include <iostream>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <sstream>
#include <string>
#include <map>
#include <set>
#include <stdlib.h>
#include <cmath>
#include <math.h>
#include <fstream>
#include <bitset>
#include <queue>
#include <ctime>
#define int long long
using namespace std;
int32_t main(){
	string s1, s2;
	cin >> s1 >> s2;
	vector<vector<int> > v, v1;
	int n = s1.size();
	bool e1 = false, e2 = false;
	for (int i=0; i < n; i++){
		if (s1[i] == '1') e1 = true;
		if (s2[i] == '1') e2 = true;
	}
	if (!e2){
		if (!e1) cout << 0 << endl;
		else cout << -1 << endl;
		return 0;
	}
	for (int i=0; i < n; i++){
        vector<int> help;
        if (s1[i] == '0'){
			continue;
        }
        int j = i;
        int counter = 0;
        while (true){
			if (s2[j] == '1') break;
			counter ++;
			j--;
			if (j < 0) j += n;
        }
        help.push_back(counter);
        int cold = counter;
        j = i;
        counter = 0;
        while (true){
			if (s2[j] == '1') break;
			counter ++;
			j++;
			if (j >= n) j -= n;
        }
        help.push_back(counter);
        help.push_back(i);
        vector<int> hh;
        hh.push_back(counter);
        hh.push_back(cold);
        hh.push_back(i);
        v.push_back(help);
        v1.push_back(hh);
	}
	sort(v.begin(), v.end());
	sort(v1.begin(), v1.end());
	int ans = 1e9;
	for (int start = 0; start < n; start++){
		vector<int> ind, ind1;
		int del = 0;
		for (int j=0; j < v.size(); j++){
            int pos = (v[j][2] - start) % n;
            if (pos < 0) pos += n;
            if (s2[pos] == '1'){
				continue;
            }
            ind.push_back(j);
		}
		for (int j=0; j < v1.size(); j++){
            int pos = (v1[j][2] - start) % n;
            if (pos < 0) pos += n;
            if (s2[pos] == '1'){
				continue;
            }
            ind1.push_back(j);
		}
		for (int j=0; j < n; j++){
			if (s2[j] == '0') continue;
			int pos = (j + start) % n;
			if (s1[pos] == '0') del++;
		}
		int th = ind.size();
        int ls = start;
        vector<int> rmax(th), lmax(th);
        for (int i=th-1; i >= 0; i--){
            if (i == th-1) rmax[i] = v[ind[i]][1];
            else rmax[i] = max(rmax[i+1], v[ind[i]][1]);
        }
        for (int i=th-1; i >= 0; i--){
            if (i == th-1) lmax[i] = v1[ind1[i]][1];
            else lmax[i] = max(lmax[i+1], v1[ind1[i]][1]);
        }
        int bp = 1e9;
        int ll = 0, rr=0;
        for (int eat=0; eat <= th; eat++){
            int lm = ll;
            if (eat > 0) lm = max(lm, v[ind[eat-1]][0]);
            int rm = 0;
            if (eat < th) rm = rmax[eat] + lm;
            int tut = lm + rm;
            int lll = (ls - lm + rm) % n;
            if (lll < 0) lll += n;
            tut += min(lll, n-lll);
            bp = min(bp, tut);
            ll = lm;
        }
        for (int eat=0; eat <= th; eat++){
            int rm = rr;
            if (eat > 0) rm = max(rm, v1[ind1[eat-1]][0]);
            int lm = 0;
            if (eat < th) lm = lmax[eat] + rm;
            int tut = lm + rm;
            int lll = (ls - lm + rm) % n;
            if (lll < 0) lll += n;
            tut += min(lll, n-lll);
            bp = min(bp, tut);
            rr = rm;
        }
        th += bp + del;
        ans = min(ans, th);
        th -= (bp + del);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 512