#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<set>
#include<queue>
#include<stack>
#include<bitset>
#include<functional>
#include<map>
#include<unordered_set> 
#include<cmath>
using namespace std;
long long p  = 998244353;
//long long p = 1000000007;
#define int long long
#define vel vector<long long>
#define vvel vector<vel>
#define rep(i,n) for(int i=0;i<n;i++)
#define sor(v) sort(v.begin(),v.end())
#define mmax(a,b) a=max(a,b)
#define mmin(a,b) a=min(a,b)
#define mkp make_pair
#define pin pair<int,int>
#define qin pair<int,pin>
#define V vector
#define Endl endl
#define veb vector<bool>
#define rev(s) reverse(s.begin(),s.end())
#define lower(h,val) lower_bound(h.begin(),h.end(),val)
#define upper(h,val) upper_bound(h.begin(),h.end(),val)
#define mint modint<998244353>
#define end_s(a) cout <<a<<endl;return 0
template <std::uint_fast64_t Modulus> class modint {
	using u64 = std::uint_fast64_t;

public:
	u64 a;

	constexpr modint(const u64 x = 0) noexcept : a(x % Modulus) {}
	constexpr u64 &value() noexcept { return a; }
	constexpr const u64 &value() const noexcept { return a; }
	constexpr modint operator+(const modint rhs) const noexcept {
		return modint(*this) += rhs;
	}
	constexpr modint operator-(const modint rhs) const noexcept {
		return modint(*this) -= rhs;
	}
	constexpr modint operator*(const modint rhs) const noexcept {
		return modint(*this) *= rhs;
	}
	constexpr modint operator/(const modint rhs) const noexcept {
		return modint(*this) /= rhs;
	}
	constexpr modint &operator+=(const modint rhs) noexcept {
		a += rhs.a;
		if (a >= Modulus) {
			a -= Modulus;
		}
		return *this;
	}
	constexpr modint &operator-=(const modint rhs) noexcept {
		if (a < rhs.a) {
			a += Modulus;
		}
		a -= rhs.a;
		return *this;
	}
	constexpr modint &operator*=(const modint rhs) noexcept {
		a = a * rhs.a % Modulus;
		return *this;
	}
	constexpr modint &operator/=(modint rhs) noexcept {
		u64 exp = Modulus - 2;
		while (exp) {
			if (exp % 2) {
				*this *= rhs;
			}
			rhs *= rhs;
			exp /= 2;
		}
		return *this;
	}
};
vel pa;
int root(int x) {
	if (pa[x] == -1) { return x; }
	int ans = root(pa[x]); pa[x] = ans;
	return ans;
}
void marge(int x, int y) {
	x = root(x);
	y = root(y);
	if (x != y) {pa[x] = y;}
}
signed main(){
	string aa, bb; cin >> aa >> bb;
	int n = aa.size();
	vel a(n), b(n);
	rep(i, n) {
		a[i] = aa[i] - '0';
		b[i] = bb[i] - '0';
	}
	vel c(n, 0);
	if (b == c) {
		if (a == c) { end_s(0); }
		end_s(-1);
	}
	vel c_b;
	rep(i, n) {
		if (b[i] == 1) {
			c_b.push_back(i - n);
			c_b.push_back(i);
			c_b.push_back(i + n);
		}
	}
	sor(c_b);
	vel le(n), ri(n);
	rep(i, n) {
		auto itr = lower_bound(c_b.begin(), c_b.end(), i);
		ri[i] = *itr;
		itr = upper_bound(c_b.begin(), c_b.end(), i);
		itr--;
		le[i] = *itr;
		ri[i] = ri[i] - i;
		le[i] = i - le[i];
	}
	int ans = 4*n*n+10*n;
	for (int ml = 1; ml <= 2*n; ml++) {
		int dif = (-ml) % n; dif += n;
		vel cha;
		rep(i, n) {
			if (a[i] != b[(i + dif) % n]) {
				cha.push_back(i);
			}
		}
		int qml = ml;
		priority_queue<pin> ch;
		for (auto x : cha) { ch.push(mkp(ri[x], x)); }
		for(int mr=2*n;mr>=0;mr--) {
			while (!ch.empty()) {
				pin y = ch.top();
				if (y.first <= mr) { break; }
				mmax(qml, le[y.second]);
				ch.pop();
			}
			int sz = cha.size();
			mmin(ans, sz + 2*qml-ml + 2*mr);
		}
	}
	for (int mr = 0; mr <= 2 * n; mr++) {
		int dif = mr % n;
		vel cha;
		rep(i, n) {
			if (a[i] != b[(i + dif) % n]) {
				cha.push_back(i);
			}
		}
		int qmr = mr;
		priority_queue<pin> ch;
		for (auto x : cha) { ch.push(mkp(le[x], x)); }
		for (int ml = 2 * n; ml >= 0; ml--) {
			while (!ch.empty()) {
				pin y = ch.top();
				if (y.first <= ml) { break; }
				mmax(qmr, ri[y.second]);
				ch.pop();
			}
			int sz = cha.size();
			mmin(ans, sz + 2 * qmr - mr + 2 * ml);
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 512