#include<bits/stdc++.h>

#define HEAP priority_queue
#define rep(i, n) for(int i = 0, _end_ = (n); i < _end_; ++i)
#define per(i, n) for(int i = (n) - 1; i >= 0 ; --i)
#define forn(i, l, r) for(int i = (l), _end_ = (r); i <= _end_; ++i)
#define nrof(i, r, l) for(int i = (r), _end_ = (l); i >= _end_; --i)
#define FOR(a, b) for(auto (a): (b))
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define X first
#define Y second
#define eps 1e-6
#define pi 3.1415926535897932384626433832795
#define SZ(x) (int)x.size()
#define ALL(x) x.begin(), x.end()

using namespace std;

typedef long long LL;
typedef double flt;
typedef vector<int> vi;
typedef vector<LL> vl;
typedef pair<int,int> pii;
typedef pair<int,LL> pil;
typedef pair<LL,int> pli;
typedef pair<LL,LL> pll;
typedef vector<pil> vil;
typedef vector<pii> vii;
typedef vector<pli> vli;
typedef vector<pll> vll;

const int iinf = 1e9 + 7;
const int oo = 0x3f3f3f3f;
const LL linf = 1ll << 60;
const flt dinf = 1e60;

template <typename T> inline void scf(T &x)
{
	bool f = 0;
	x = 0;
	char c = getchar();
	while(c != '-' && (c < '0' || c > '9')) c = getchar();
	if(c == '-') f = 1, c = getchar();
	while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	if(f) x = -x;
	return;
}

template <typename T1, typename T2> void scf(T1 &x, T2 &y)
{
	scf(x);
	return scf(y);
}

template <typename T1, typename T2, typename T3> void scf(T1 &x, T2 &y, T3 &z)
{
	scf(x);
	scf(y);
	return scf(z);
}

template <typename T1, typename T2, typename T3, typename T4> void scf(T1 &x, T2 &y, T3 &z, T4 &w)
{
	scf(x);
	scf(y);
	scf(z);
	return scf(w);
}

inline char mygetchar()
{
	char c = getchar();
	while(c == ' ' || c == '\n') c = getchar();
	return c;
}

template <typename T> inline bool chkmax(T &x, const T &y)
{
	return y > x ? x = y, 1 : 0;
}

template <typename T> inline bool chkmin(T &x, const T &y)
{
	return y < x ? x = y, 1 : 0;
}

#ifdef King_George
#define DEBUG
#define debug(...) fprintf(stderr, __VA_ARGS__)
#else
#define debug(...)
#endif

//---------------------------------------------------------head----------------------------------------------------

const int maxn = 2030;

int n;
char a[maxn], b[maxn];
int cnt[maxn], nxt[maxn], lst[maxn];
int x[maxn], y[maxn];
vi v[maxn];

int calc()
{
	int ret = 0, mx = 0;
#ifdef DEBUG
	forn(i, 1, n) printf("%d %d\n", x[i], y[i]);
#endif
	forn(i, 1, n) if(x[i]) v[x[i]].pb(i), chkmax(ret, x[i]);
	nrof(i, n, 1)
	{
		for(int &j: v[i]) chkmax(mx, y[j]);
		v[i].clear();
		debug("\t%d %d\n", i, mx);
		chkmin(ret, i + mx - 1);
		debug("ret = %d\n", ret);
	}
	return ret;
}

int main()
{
	scanf("%s", a + 1);
	scanf("%s", b + 1);
	n = strlen(a + 1);
	forn(i, 1, n) cnt[i] = cnt[i - 1] + (b[i] == '1');
	if(cnt[n] == 0)
	{
		forn(i, 1, n) if(a[i] == '1')
		{
			puts("-1");
			return 0;
		}
		puts("0");
		return 0;
	}
	forn(i, 1, n)
	{
		int j = i;
		while(b[j] == '0')
		{
			++j;
			if(j > n) j = 1;
		}
		nxt[i] = j;
		debug("nxt[%d] = %d\n", i, j);
	}
	forn(i, 1, n)
	{
		int j = i;
		while(b[j] == '0')
		{
			--j;
			if(j == 0) j = n;
		}
		lst[i] = j;
	}
	int ans = iinf;
	forn(beg, 1, n)
	{
		memset(x, 0, sizeof(x[0]) * (n + 1));
		memset(y, 0, sizeof(y[0]) * (n + 1));
		int dlt = beg - 1;
		forn(i, 1, n)
		{
			int j = i + beg - 1;
			while(j > n) j -= n;
			if(a[i] != b[j])
			{
				int lb = i, rb = j;
				debug("\t%d %d\n", j, nxt[j]);
				if(lb <= rb)
				{
					if(cnt[lb - 1] == cnt[rb])
					{
						debug("\t%d %d\n", j, nxt[j]);
						if(nxt[j] < j) x[i] = nxt[j] + n - j;
						else x[i] = nxt[j] - j;
					}
				}
				else
				{
					if(!cnt[rb] && cnt[n] == cnt[lb - 1])
					{
						debug("\t%d %d %d\n", i, j, nxt[j]);
						if(nxt[j] < j) x[i] = nxt[j] + n - j;
						else x[i] = nxt[j] - j;
					}
				}
			}
		}
		debug("%d\n", x[5]);
		forn(i, 1, n)
		{
			int j = i + beg - 1;
			while(j > n) j -= n;
			if(a[i] != b[j])
			{
				++dlt;
				int lb = i, rb = j;
				if(lb <= rb)
				{
					if(cnt[lb - 1] == cnt[rb])
					{
						if(lst[i] <= i) y[i] = i - lst[i];
						else y[i] = i + n - lst[i];
					}
				}
				else
				{
					if(!cnt[rb] && cnt[n] == cnt[lb - 1])
					{
						if(lst[i] <= i) y[i] = i - lst[i];
						else y[i] =  i + n - lst[i];
					}
				}
			}
		}
		debug("%d\n", x[5]);
		chkmin(ans, dlt + calc() * 2);
	}
	forn(i, 1, n)
	{
		int j = n + 1 - i;
		if(j <= i) break;
		swap(a[i], a[j]);
		swap(b[i], b[j]);
	}
	memset(cnt, 0, sizeof cnt);
	memset(nxt, 0, sizeof nxt);
	memset(lst, 0, sizeof lst);
	forn(i, 1, n) cnt[i] = cnt[i - 1] + (b[i] == '1');
	forn(i, 1, n)
	{
		int j = i;
		while(b[j] == '0')
		{
			++j;
			if(j > n) j = 1;
		}
		nxt[i] = j;
	}
	forn(i, 1, n)
	{
		int j = i;
		while(b[j] == '0')
		{
			--j;
			if(j == 0) j = n;
		}
		lst[i] = j;
	}
	forn(beg, 1, n)
	{
		memset(x, 0, sizeof(x[0]) * (n + 1));
		memset(y, 0, sizeof(y[0]) * (n + 1));
		int dlt = beg - 1;
		forn(i, 1, n)
		{
			int j = i + beg - 1;
			while(j > n) j -= n;
			if(a[i] != b[j])
			{
				int lb = i, rb = j;
				if(lb <= rb)
				{
					if(cnt[lb - 1] == cnt[rb])
					{
						if(nxt[j] < j) x[i] = nxt[j] + n - j;
						else x[i] = nxt[j] - j;
					}
				}
				else
				{
					if(!cnt[rb] && cnt[n] == cnt[lb - 1])
					{
						if(nxt[j] < j) x[i] = nxt[j] + n - j;
						else x[i] = nxt[j] - j;
					}
				}
			}
		}
		forn(i, 1, n)
		{
			int j = i + beg - 1;
			while(j > n) j -= n;
			if(a[i] != b[j])
			{
				++dlt;
				int lb = i, rb = j;
				if(lb <= rb)
				{
					if(cnt[lb - 1] == cnt[rb])
					{
						if(lst[i] <= i) y[i] = i - lst[i];
						else y[i] = i + n - lst[i];
					}
				}
				else
				{
					if(!cnt[rb] && cnt[n] == cnt[lb - 1])
					{
						if(lst[i] <= i) y[i] = i - lst[i];
						else y[i] = i + n - lst[i];
					}
				}
			}
		}
		chkmin(ans, dlt + calc() * 2);
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 384