#include <cstdio>
#include <cstring>
#include <algorithm>

const int Inf = 0x3f3f3f3f;
const int MN = 2005;

int N;
char s[MN], t[MN];

int A[MN], B[MN], L[MN], R[MN], dl[MN], dr[MN], p[MN], suf[MN];
inline int Solve(int r) {
	int ret = 0, lb = 0, rb = 0, K = 0;
	if (r >= 0) ret = r, rb = r;
	else ret = -r, lb = r;
	for (int i = 1; i <= N; ++i) {
		if (A[i] == B[(((i + r) % N + N - 1) % N) + 1]) continue;
		++ret;
		if (lb <= L[i] || R[i] <= rb) continue;
		dl[++K] = lb - L[i], dr[K] = R[i] - rb, p[K] = K;
	}
	std::sort(p + 1, p + K + 1, [](int i, int j) { return dl[i] < dl[j]; });
	suf[K + 1] = 0;
	for (int i = K; i >= 1; --i) suf[i] = std::max(suf[i + 1], dr[p[i]]);
	int mnv = suf[1];
	for (int i = 1, val = 0; i <= K; ++i)
		val = std::max(val, dl[p[i]]),
		mnv = std::min(mnv, val + suf[i + 1]);
	return ret + 2 * mnv;
}

int main() {
	scanf("%s%s", s + 1, t + 1), N = strlen(s + 1);
	int ok = 0;
	for (int i = 1; i <= N; ++i) if (t[i] == '1') ok = 1;
	if (!ok) {
		for (int i = 1; i <= N; ++i) if (s[i] == '1') return puts("-1"), 0;
		return puts("0"), 0;
	}
	for (int i = 1; i <= N; ++i)
		A[i] = s[i] - '0', B[i] = t[i] - '0';
	for (int i = 1, x, y; i <= N; ++i) {
		x = y = i;
		while (!B[x]) --L[i], x = x > 1 ? x - 1 : N;
		while (!B[y]) ++R[i], y = y < N ? y + 1 : 1;
	}
	int Ans = Inf;
	for (int r = 1 - 2 * N; r <= 2 * N - 1; ++r)
		Ans = std::min(Ans, Solve(r));
	printf("%d\n", Ans);
	return 0;
}