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

#define rep(i, N) for (int i = 0; i < N; i++)
#define pb push_back
typedef long long ll;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
const int MOD = 1e9 + 7;
const int INF = INT_MAX / 2;
struct edge { int v, w; };

int c[2010][2010], sum[2010][2010];

int solve(int N, vector<bool> a, vector<bool> b) {
	vector<int> dp(N);
	rep(d, N) rep(i, N) if (a[(i + d) % N] != b[i]) dp[d]++;
	vector<i_i> p;
	rep(i, N) if (a[i]) {
		int l, r;
		for (l = 0; !b[(i + l + N) % N]; l++);
		for (r = 0; !b[(i - r + N) % N]; r++);
		p.pb(i_i(l, r));
	}
	int mi = INT_MAX / 2;
	rep(l0, N * 2) {
		int r0 = -1;
		for (i_i z: p) if (z.first > l0) r0 = max(r0, z.second);
		int i0, ans;
		if (r0 == -1) i0 = -l0, ans = l0;
		else i0 = r0, ans = l0 + l0 + r0;
		rep(i, N) {
			int d = abs(i - i0) % N;
			d = min(d, N - d);
			mi = min(mi, ans + d + dp[i]);
		}
	}
	return mi;
}

int main() {
	string s, t; cin >> s >> t;
	int N = s.length();
	vector<bool> a(N), b(N);
	rep(i, N) a[i] = (s[i] == '1'), b[i] = (t[i] == '1');
	bool ok = false;
	rep(i, N) if (b[i]) ok = true;
	if (!ok) {
		cout << (a == b ? 0 : -1) << endl;
		return 0;
	}
	int ans = solve(N, a, b);
	reverse(a.begin(), a.end());
	reverse(b.begin(), b.end());
	ans = min(ans, solve(N, a, b));
	cout << ans << endl;
}
