#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define repp(i, m, n) for(int i = m; i < n; i++)
#define reps(i, n) for(int i = 1; i <= n; i++)
const int    INF = 100000000;
const double EPS = 1e-10;
const int    MOD = 1000000007;
using namespace std;
typedef long long ll;
typedef pair<int, int> pai;
typedef pair<ll,ll> pal;



int main()
{
	string A, B;
	cin >> A >> B;
	int n=A.size();

	bool a[2010], b[6030];
	rep(i, n)
	{
		if(A[i]=='0') a[i]=0;
		else a[i]=1;
		if(B[i]=='0') b[i]=b[i+n]=b[i+2*n]=0;
		else b[i]=b[i+n]=b[i+2*n]=1;
	}
	int l[2010], r[2010];
	int left, right;
	bool muri=0;
	rep(i, n)
	{
		left=right=0;
		while(b[i+n-left]==0 && left<n)
		{
			left++;
		}
		while(b[i+n+right]==0 && right<n)
		{
			right++;
		}
		l[i]=left;
		r[i]=right;
		if(l[i]==n || r[i]==n) muri=1;
	}
	if(muri)
	{
		bool murii=0;
		rep(i, n)
		{
			if(a[i]==1)
			{
				murii=1;
				break;
			}
		}
		if(murii) cout << "-1" << endl;
		else cout << "0" << endl;
	}
	else
	{
		bool dif[2010];
		int ans=INF;
		int tmp1, tmp2;
		int ml, mr;
		rep(k, n)
		{
			vector<int> s[2010], t[2010];
			tmp1=0;
			rep(i, n)
			{
				if(a[i]!=b[i+k]) dif[i]=1, tmp1++;
				else dif[i]=0;
			}
			ml=mr=0;
			rep(i, n)
			{
				if(dif[i])
				{
					if(k<r[i])
					{
						ml=max(ml, l[i]);
						s[l[i]].push_back(r[i]-k);
					}
					if(n-k<l[i])
					{
						mr=max(mr, l[i]);
						t[r[i]].push_back(l[i]-(n-k));
					}
				}
			}
			tmp2=min(2*ml+k, 2*mr+(n-k));
			int rmm=0, lmm=0;
			for(int j=ml; j>0; j--)
			{
				rep(m, s[j].size()) rmm=max(rmm, s[j][m]);
				tmp2=min(tmp2, 2*(j-1)+k+2*rmm);
			}
			for(int j=mr; j>0; j--)
			{
				rep(m, t[j].size()) lmm=max(lmm, t[j][m]);
				tmp2=min(tmp2, 2*(j-1)+(n-k)+2*lmm);
			}
			ans=min(ans, tmp1+tmp2);
		}
		cout << ans << endl;
	}
	return 0;
}