#include <bits/stdc++.h>
#define f first
#define s second
using namespace std;
using ll = long long;
using ii = pair<int, int>;
constexpr int MN = 2002;

int N, ans = 1e9;

void solve(string A, string B) {
	vector<int> v(1);
	for (int i = 0; i < N; ++i)
		if (B[i] == '1') v.push_back(i);
	v[0] = v.back()-N, v.push_back(v[1]+N);
	ii P[MN];
	for (int i = 0; i < N; ++i) {
		auto it = lower_bound(begin(v), end(v), i);
		P[i] = ii(*prev(it), *it);
	}

	for (int i = 0; i < N; ++i) {
		int cnt = 0;
		for (int j = 0; j < N; ++j)
			if (A[j] != B[j]) ++cnt;
		vector<ii> s;
		for (int j = 0; j < N; ++j)
			if (A[j] == '1' && B[j] == '0')
				s.emplace_back(j-P[j].f, P[j].s-j);
		sort(begin(s), end(s)),	reverse(begin(s), end(s));
		s.emplace_back(0, 0);

		if (s.size()) {
			int l = s[0].f, r = 0;
			for (int j = 0; j < s.size(); ++j) {
				ans = min(2*max(l-i, 0)+i+2*r+cnt, ans);
				if (j == s.size()-1) break;
				l = s[j+1].f;
				r = max(s[j].s, r);
			}
		}
		else {
			ans = min(cnt, ans);
		}
		rotate(begin(A), begin(A)+N-1, end(A));
	}
}

int main() {
	if (fopen("in", "r")) freopen("in", "r", stdin), freopen("out", "w", stdout);
	ios_base::sync_with_stdio(0), cin.tie(0);

	string A, B; cin >> A >> B;
	N = A.size();
	if (B == string(N, '0')) {
		cout << (A == string(N, '0') ? 0 : -1);
		return 0;
	}
	solve(A, B);
	reverse(begin(A), end(A)), reverse(begin(B), end(B));
	solve(A, B);
	cout << ans;
}
