#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pii> pip;
const ll INF = 1e9+100;
const ll MOD = 1e9;
const double EPS = 1e-10;
const bool debug = 0;
//------------------------------//

template <typename T>
struct SegTree {
	T init_val;
	int n;
	vector<T> dat;
	
	SegTree(int _n, T init_val) {
		init(_n, init_val);
	}
	
	void init(int _n, T init_val) {
		this->init_val = init_val;
		n = 1;
		while (n < _n) n *= 2;
		dat.resize(n * 2 - 1, init_val);
	}
	
	void update(int i, T x) {
		i += n - 1;
		dat[i] = max(dat[i], x);
		while (i > 0) {
			i = (i - 1) / 2;
			dat[i] = max(dat[i * 2 + 1], dat[i * 2 + 2]);
		}
	}
	
	void set(int i, T x) {
		dat[i + n - 1] = x;
		update(i, x);
	}
	
	// 探索範囲[a,b), 現在見ているkノード[l,r)
	T query(int a, int b, int k = 0, int l = 0, int r = -1) {
		if (r < 0) r = n;
		
		if (r <= a || b <= l) return init_val;
		if (a <= l && r <= b) return dat[k];
		return max( query(a, b, k * 2 + 1, l, (l + r) / 2), query(a, b, k * 2 + 2, (l + r) / 2, r) );
	}
};

string a, b;
int dl[2000], dr[2000];
int N;

inline int midist(int st, int ed) {
	st = (st + N) % N;
	ed = (ed + N) % N;
	return min((ed - st + N) % N, N - (ed - st + N) % N);
}

int main() {
	cin >> a >> b;
	
	if (count(ALL(b), '1') == 0) {
		if (count(ALL(a), '1') == 0) puts("0");
		else puts("-1");
		return 0;
	}
	
	N = a.size();
	
	queue<int> que;
	
	memset(dl, -1, sizeof(dl));
	REP(i, N) {
		if (b[i] == '1') {
			que.push(i);
			dl[i] = 0;
		}
	}
	while (!que.empty()) {
		int p = que.front(); que.pop();
		int nexp = (p + 1) % N;
		if (dl[nexp] != -1) continue;
		que.push(nexp);
		dl[nexp] = dl[p] + 1;
	}
	
	memset(dr, -1, sizeof(dr));
	REP(i, N) {
		if (b[i] == '1') {
			que.push(i);
			dr[i] = 0;
		}
	}
	while (!que.empty()) {
		int p = que.front(); que.pop();
		int nexp = (p - 1 + N) % N;
		if (dr[nexp] != -1) continue;
		que.push(nexp);
		dr[nexp] = dr[p] + 1;
	}
	
	int ans = INF;
	
	REP(i, N) {
		
		// right: x, left: ?, adjust: closer
		int now = 0;
		vector<pii> v;
		REP(j, N) {
			if (a[(i + j) % N] != b[j]) {
				now++;
				v.push_back(pii(dr[(i + j) % N], dl[(i + j) % N]));
			}
		}
		sort(ALL(v));
		
		SegTree<int> seg(2100, 0);
		vector<int> cnt(2100, 0);
		REP(j, v.size()) {
			if (cnt[v[j].se]++ == 0) {
				seg.update(v[j].se, v[j].se);
			}
		}
		
		chmin(ans, now + seg.query(0, 2100) + midist(-seg.query(0, 2100), -i));
		chmin(ans, now + N + midist(N, -i));
		REP(j, v.size()) {
			if (--cnt[v[j].se] == 0) seg.set(v[j].se, 0);
			chmin(ans, now + 2 * v[j].fi + seg.query(0, 2100) + midist(-seg.query(0, 2100), -i));
		}
		
		// right: ?, left: x, adjust: closer
		v.clear();
		REP(j, N) {
			if (a[(i + j) % N] != b[j]) {
				v.push_back(pii(dl[(i + j) % N], dr[(i + j) % N]));
			}
		}
		sort(ALL(v));
		
		seg.init(2100, 0);
		cnt.resize(2100, 0);
		REP(j, v.size()) {
			if (cnt[v[j].se]++ == 0) {
				seg.update(v[j].se, v[j].se);
			}
		}
		
		chmin(ans, now + seg.query(0, 2100) + midist(seg.query(0, 2100), -i));
		REP(j, v.size()) {
			if (--cnt[v[j].se] == 0) seg.set(v[j].se, 0);
			chmin(ans, now + 2 * v[j].fi + seg.query(0, 2100) + midist(seg.query(0, 2100), -i));
		}
	}
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 384