#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define pb push_back
using namespace std;
const int inf=1e9+7;
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;}
const int N=2005;
char a[N],b[N];
int cnt[N],nxt[N],lst[N];
int x[N],y[N],n;
vector<int> v[N];
int calc()
{
	int ret=0,mx=0;
	rep(i,1,n) if(x[i]) v[x[i]].pb(i),chkmax(ret,x[i]);
	per(i,n,1)
	{
		for(int k=0;k<v[i].size();k++) chkmax(mx,y[v[i][k]]);
		v[i].clear();
		chkmin(ret,i+mx-1);
	}
	return ret;
}
int main()
{
	scanf("%s",a+1);
	scanf("%s",b+1);
	n=strlen(a+1);
	rep(i,1,n) cnt[i]=cnt[i-1]+(b[i]=='1');
	if(!cnt[n])
	{
		rep(i,1,n) if(a[i]=='1')
		{
			puts("-1");
			return 0;
		}
		puts("0");
		return 0;
	}
	rep(i,1,n)
	{
		int j=i;
		while(b[j]=='0')
		{
			++j;
			if(j>n) j=1;
		}
		nxt[i]=j;
	}
	rep(i,1,n)
	{
		int j=i;
		while(b[j]=='0')
		{
			--j;
			if(j==0) j=n;
		}
		lst[i]=j;
	}
	int ans=inf;
	rep(T,1,n)
	{
		memset(x,0,sizeof(x[0])*(n+1));
		memset(y,0,sizeof(y[0])*(n+1));
		int xjt=T-1;
		rep(i,1,n)
		{
			int j=i+T-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;
					}
				}
			}
		}
		rep(i,1,n)
		{
			int j=i+T-1;
			while(j>n) j-=n;
			if(a[i]!=b[j])
			{
				++xjt;
				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,xjt+calc()*2);
	}
	rep(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));
	rep(i,1,n) cnt[i]=cnt[i-1]+(b[i]=='1');
	rep(i,1,n)
	{
		int j=i;
		while(b[j]=='0')
		{
			++j;
			if(j>n) j=1;
		}
		nxt[i]=j;
	}
	rep(i,1,n)
	{
		int j=i;
		while(b[j]=='0')
		{
			--j;
			if(j==0) j=n;
		}
		lst[i]=j;
	}
	rep(T,1,n)
	{
		memset(x,0,sizeof(x));
		memset(y,0,sizeof(y));
		int xjt=T-1;
		rep(i,1,n)
		{
			int j=i+T-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;
					}
				}
			}
		}
		rep(i,1,n)
		{
			int j=i+T-1;
			while(j>n) j-=n;
			if(a[i]!=b[j])
			{
				++xjt;
				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,xjt+calc()*2);
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 384