#include <string>
#include <iostream>
#include <algorithm>
using namespace std;
int n, pre[2009], nxt[2009], val[2009], v1[2009], v2[2009]; string a, b;
int main() {
	cin >> a >> b; n = a.size();
	if (b.find('1') == string::npos) cout << (a == b ? 0 : -1) << endl;
	else {
		int ret = 1 << 30;
		for (int i = 0; i < 2; i++) {
			for (int j = 0; j < n; j++) {
				if (b[j] == '1') {
					a = a.substr(j) + a.substr(0, j);
					b = b.substr(j) + b.substr(0, j);
					break;
				}
			}
			for (int j = 0; j < n; j++) pre[j] = (b[j] == '1' ? 0 : pre[j - 1] + 1);
			for (int j = n - 1; j >= 0; j--) nxt[j] = (b[j] == '1' ? 0 : nxt[j + 1] + 1);
			fill(val, val + n, 0);
			for (int j = 0; j < n; j++) {
				if (a[j] == '0') pre[j] = nxt[j] = 0;
				val[pre[j]] = max(val[pre[j]], nxt[j]);
			}
			for (int j = n - 1; j >= 0; j--) val[j] = max(val[j], val[j + 1]);
			fill(v1, v1 + n, 1 << 30);
			fill(v2, v2 + n, 1 << 30);
			for (int j = 1; j <= n; j++) {
				v1[val[j]] = min(v1[val[j]], (j - 1) * 2 + val[j] * 2);
				v2[val[j]] = min(v2[val[j]], (j - 1) * 2);
			}
			for (int j = n - 2; j >= 0; j--) v1[j] = min(v1[j], v1[j + 1]);
			int cl = 1 << 30;
			for (int j = 0; j < n; j++) {
				int cnt = 0;
				for (int k = 0; k < n; k++) {
					if (a[k] != b[(j + k) % n]) cnt++;
				}
				cl = min(cl, v2[j]);
				ret = min(ret, cnt + cl + j);
				ret = min(ret, cnt + v1[j] - j);
			}
			reverse(a.begin(), a.end());
			reverse(b.begin(), b.end());
		}
		cout << ret << endl;
	}
	return 0;
}