#include <cstdio>
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <ctime>
#include <cstring>
#include <cassert>
#include <bitset>
#include <sstream>
#include <queue>

#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define sz(a) ((int) (a).size())
#define eprintf(...) fprintf(stderr, __VA_ARGS__)

using namespace std;

typedef long long int64;
typedef long double ldb;

const long double eps = 1e-9;
const int inf = (1 << 30) - 1;
const long long inf64 = ((long long)1 << 62) - 1;
const long double pi = acos(-1);

template <class T> T sqr (T x) {return x * x;}
template <class T> T abs (T x) {return x < 0 ? -x : x;}

int main () {
    ios_base::sync_with_stdio(0);
//	freopen("input.txt", "rt", stdin);
//	freopen("output.txt", "wt", stdout);

	string sa, sb;
	cin >> sa >> sb;
	
	int n = sz(sa);
	vector<int> a(n);
	vector<int> b(n);
	for (int i = 0; i < n; ++i) {
		a[i] = sa[i] - '0';
		b[i] = sb[i] - '0';
	}

	bool key_a = false;
	bool key_b = false;
	for (int i = 0; i < n; ++i) {
		key_a |= a[i] == 1;
		key_b |= b[i] == 1;
	}

	if (!key_b) {
		cout << (key_a ? -1 : 0) << endl;
		return 0;
	}

	vector<int> next(n);
	if (b[n - 1] == 1) {
		next[n - 1] = n - 1;
	} else {
		for (int i = 0; i < n; ++i) {
			if (b[i] == 1) {
				next[n - 1] = n + i;
				break;
			}
		}
	}
	for (int i = n - 2; i >= 0; --i) {
		if (b[i] == 1) {
			next[i] = i;
		} else {
			next[i] = next[i + 1];
		}
    }

    vector<int> prev(n);
    if (b[0] == 1) {
    	prev[0] = 0;
    } else {
    	for (int i = n - 1; i >= 0; --i) {
    		if (b[i] == 1) {
    			prev[0] = i - n;
    			break;
    		}
    	}
    }
    for (int i = 1; i < n; ++i) {
    	if (b[i] == 1) {
    		prev[i] = i;
    	} else {
    		prev[i] = prev[i - 1];
    	}
    }

    int res = inf;
    vector<int> back_forward(n, 0);
    for (int sh_b = 0; sh_b < n; ++sh_b) {
    	int dif = 0;
    	
    	for (int i = 0; i < n; ++i) {
    		back_forward[i] = 0;
    	}
    	for (int i = 0; i < n; ++i) {
    		if (a[(i + sh_b) % n] == b[i]) {
    			continue;
    		}

    		++dif;
    		if (next[i] <= i + sh_b) {
    			continue;
    		}

    		int cur_back = next[i] - (i + sh_b);
    		int cur_forward = i - prev[i];

    		back_forward[cur_back] = max(back_forward[cur_back], cur_forward);
    	}

    	for (int i = n - 2; i >= 0; --i) {
    		back_forward[i] = max(back_forward[i], back_forward[i + 1]);
    	}

    	res = min(res, sh_b + dif + 2 * (n - 1));
        for (int i = 0; i < n - 1; ++i) {
        	res = min(res, sh_b + dif + 2 * (i + back_forward[i + 1]));
    	}
    }

    for (int sh_f = 1; sh_f < n; ++sh_f) {
		int dif = 0;
    	
    	for (int i = 0; i < n; ++i) {
    		back_forward[i] = 0;
    	}
    	for (int i = 0; i < n; ++i) {
    		if (a[(i - sh_f + n) % n] == b[i]) {
    			continue;
    		}

    		++dif;
    		if (prev[i] >= i - sh_f) {
    			continue;
    		}

    		int cur_back = next[i] - i;
    		int cur_forward = (i - sh_f) - prev[i];

    		back_forward[cur_back] = max(back_forward[cur_back], cur_forward);
    	}

        for (int i = n - 2; i >= 0; --i) {
    		back_forward[i] = max(back_forward[i], back_forward[i + 1]);
    	}

    	res = min(res, sh_f + dif + 2 * (n - 1));
        for (int i = 0; i < n - 1; ++i) {
        	res = min(res, sh_f + dif + 2 * (i + back_forward[i + 1]));
    	}
    }

    cout << res << endl;

	return 0;
}


Measured memory_bytes: 256