#include <bits/stdc++.h>
using namespace std;
#define PB push_back
#define MP make_pair
#define LL long long
#define int LL
#define FOR(i,a,b) for(int i = (a); i <= (b); i++)
#define FORD(i,a,b) for(int i = (a); i >= (b); i--)
#define RE(i,n) FOR(i,1,n)
#define REP(i,n) FOR(i,0,(int)(n)-1)
#define R(i,n) REP(i,n)
#define VI vector<int>
#define PII pair<int,int>
#define LD long double
#define FI first
#define SE second
#define st FI
#define nd SE
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())

template<class C> void mini(C& _a4, C _b4) { _a4 = min(_a4, _b4); }
template<class C> void maxi(C& _a4, C _b4) { _a4 = max(_a4, _b4); }

template<class TH> void _dbg(const char *sdbg, TH h) { cerr << sdbg << '=' << h << endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
	while (*sdbg != ',')cerr << *sdbg++; cerr << '=' << h << ','; _dbg(sdbg + 1, a...);
}

template<class T> ostream& operator<<(ostream& os, vector<T> V) {
	os << "["; for (auto& vv : V) os << vv << ","; os << "]";
	return os;
}
template<class L, class R> ostream &operator<<(ostream &os, pair<L, R> P) {
	return os << "(" << P.st << "," << P.nd << ")";
}


#ifdef LOCAL
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug(...) (__VA_ARGS__)
#endif

vector<int> sum;

int n;

int ile(int l, int r) {
	if (l > r) {
		swap(l, r);
	}
	if (l < 0) {
		r += n;
		l += n;
	}
	return sum[r + 1] - sum[l];
}

int32_t main(int32_t argc, char ** argv) {
	ios_base::sync_with_stdio(0);
	string a, b;
	cin >> a >> b;
	n = a.size();
	b = b + b;
	sum.resize(2 * n + 1);
	REP(i, 2 * n) {
		sum[i + 1] = sum[i] + (b[i] == '1');
	}
	int ts = 0;
	REP(i, n) {
		if (a[i] == '1') {
			ts++;
			break;
		}
	}
	if (!sum[n] && ts) {
		cout << -1 << "\n";
		return 0;
	}

	int bestRes = INT_MAX;
	FOR(i, -n + 1, n - 1) {
		int co = abs(i);
		vector<PII> v;
		REP(j, n) {
			int pos = j + i;
			if (pos < 0) {
				pos += n;
			}
			if (pos >= n) {
				pos -= n;
			}
			if (a[j] == b[pos]) {
				continue;
			}
			pos = j + i;
			co++;
			int l, r;
			int left = min(pos, j);
			int right = max(pos, j);
			int mleft = right - n + 1;
			int mright = left + n - 1;
			int lshift = INT_MAX;
			int rshift = INT_MAX;
			{
				l = mleft - 1;
				r = left;
				while (l < r) {
					int m = (l + r + 1) / 2;
					if (ile(m, right)) {
						l = m;
					}
					else {
						r = m - 1;
					}
				}
				if (l != mleft - 1) {
					lshift = left - l;
				}
			}
			{
				l = right;
				r = mright + 1;
				while (l < r) {
					int m = (l + r) / 2;
					if (ile(left, m)) {
						r = m;
					}
					else {
						l = m + 1;
					}
				}
				if (r != mright + 1) {
					rshift = l - right;
				}
			}
			v.push_back({lshift, rshift});
		}
		if (v.empty()) {
			bestRes = min(bestRes, co);
			continue;
		}
		int bres = INT_MAX;
		multiset<int> right;
		sort(ALL(v));
		int mleft = 0;
		for (PII p : v) {
			right.insert(p.second);
		}
		bres = *--right.end();
		for (PII p : v) {
			right.erase(right.find(p.second));
			int tres = p.first;
			if (!right.empty()) {
				tres += *--right.end();
			}
			bres = min(bres, tres);
		}
  		bestRes = min(bestRes, co + 2 * bres);
	}
	cout << (bestRes == INT_MAX?-1:bestRes);
}

Measured memory_bytes: 384