#include <bits/stdc++.h>
 
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define li long long
#define itn int
 
using namespace std;
 
inline int nxt(){
	int n;
	scanf("%d", &n);
	return n;
}

template <typename T>
ostream& operator <<(ostream& ostr, const vector<T>& a) {
	ostr << "(";
	for (size_t i = 0; i < a.size(); ++i) {
		if (i) {
			ostr << ", ";
		}
		ostr << a[i];
	}
	ostr << ")";
	return ostr;
}

vector<int> pr;
int n;

int get_sum(int l, int r) {
	r += 1;
	r %= n;
	if (l < r) {
		return pr[r] - pr[l];
	} else {
		return pr[r] + pr[n] - pr[l];
	}
}

int main() {
	string a, b;
	cin >> a >> b;
	n = a.size();

	int ans = INT_MAX;
	if (b == string(n, '0') && a != b) {
		puts("-1");
		return 0;
	}

	vector<int> min_left(n, n);
	for (int i = 0; i < n; ++i) {
		if (b[i] == '1') {
			min_left[i] = 0;
		} else {
			min_left[i] = min_left[(i + n - 1) % n] + 1;
		}
	}
	for (int i = 0; min_left[i] >= n; ++i) {
		min_left[i] = min_left[(i + n - 1) % n] + 1;
	}
	vector<int> min_right(n, n);
	reverse(all(b));
	for (int i = 0; i < n; ++i) {
		if (b[i] == '1') {
			min_right[i] = 0;
		} else {
			min_right[i] = min_right[(i + n - 1) % n] + 1;
		}
	}
	for (int i = 0; min_right[i] >= n; ++i) {
		min_right[i] = min_right[(i + n - 1) % n] + 1;
	}
	reverse(all(b));
	reverse(all(min_right));

	// cerr << min_left << " " << min_right << "\n";

	pr.resize(n + 1);
	for (int i = 0; i < n; ++i) {
		pr[i + 1] = pr[i] + b[i] - '0';
	}

	for (int s = 0; s <= n; ++s) {
		vector<int> ill;
		for (int i = 0; i < n; ++i) {
			if (a[i] != b[(i + s) % n]) {
				ill.push_back(i);
			}
		}
		int L = -1, R = n - s;
		while (R > L + 1) {
			int mid = (L + R) / 2;
			vector<int> ev(n + 1);
			for (int i : ill) {
				int l = min_left[i], r = min_right[(i + s) % n];
				if (!get_sum(i, (i + s) % n)) {
					// either l >= l, or r >= r
					// can't be that l < l and r < r
					// can't be that l < l and mid - l < r
					// can't be that mid - r < l < l
					if (max(mid - r + 1, 0) < l) {
						ev[max(mid - r + 1, 0)] += 1;
						ev[l] -= 1;
					}
				}
			}
			bool ok = false;
			int bal = 0;
			for (int i = 0; i <= mid; ++i) {
				bal += ev[i];
				if (bal == 0) {
					ok = true;
				}
			}
			if (ok) {
				R = mid;
			} else {
				L = mid;
			}
		}
		ans = min(ans, s + 2 * R + (int)ill.size());

		// cerr << s << ": " << ans << "\n";
	}

	for (int s = 0; s <= n; ++s) {
		vector<int> ill;
		for (int i = 0; i < n; ++i) {
			if (a[i] != b[(i + n - s) % n]) {
				ill.push_back(i);
			}
		}
		int L = -1, R = n - s;
		while (R > L + 1) {
			int mid = (L + R) / 2;
			vector<int> ev(n + 1);
			for (int i : ill) {
				int l = min_right[i], r = min_left[(i + n - s) % n];
				if (!get_sum((i + n - s) % n, i)) {
					// either l >= l, or r >= r
					// can't be that l < l and r < r
					// can't be that l < l and mid - l < r
					// can't be that mid - r < l < l
					if (max(mid - r + 1, 0) < l) {
						ev[max(mid - r + 1, 0)] += 1;
						ev[l] -= 1;
					}
				}
			}
			bool ok = false;
			int bal = 0;
			for (int i = 0; i <= mid; ++i) {
				bal += ev[i];
				if (bal == 0) {
					ok = true;
				}
			}
			if (ok) {
				R = mid;
			} else {
				L = mid;
			}
		}
		ans = min(ans, s + 2 * R + (int)ill.size());
		// cerr << s << ": " << ans << "\n";
	}

	printf("%d\n", ans);

	return 0;
}

Measured memory_bytes: 256