// Slower C++ solution:
#include<cstdio>

#include<cstring>

#include<algorithm>

#include<vector>

#define MAXN 2000

#define INF 0x3FFFFFFF

using namespace std;

typedef pair<int,int> PII;

char A[MAXN+5],B[MAXN+5];

vector<PII> need;

int n;

int seq1[MAXN+5],seq2[MAXN+5];

int psm1[MAXN+5],psm2[MAXN+5];

int sm1[MAXN+5],sm2[MAXN+5];

int maxr[MAXN+5];

void prepare()

{

	for(int i=0;i<n;i++)

		seq2[i]=B[i]-'0';

	for(int i=0;i<n;i++)

	{

		int len=-1;

		for(int j=0;j<n;j++)

			if(seq2[(i+j)%n]==1)

			{

				len=j;

				break;

			}

		psm1[i]=len;

		len=-1;

		for(int j=0;j<n;j++)

			if(seq2[(i-j+n)%n]==1)

			{

				len=j;

				break;

			}

		psm2[i]=len;

	}

}

int solve()

{

	int ret=INF;

	sort(need.begin(),need.end());

	maxr[need.size()]=0;

	for(int i=need.size()-1;i>=0;i--)

		maxr[i]=max(maxr[i+1],need[i].second);

	ret=2*maxr[0];

	for(int i=0;i<(int)need.size();i++)

		ret=min(ret,need[i].first*2+maxr[i+1]*2);

	return ret;

}

int main()

{

	scanf("%s %s",A,B);

	n=strlen(A);

	prepare();

	int ans=INF;

	for(int mv=0;mv<n;mv++)

	{

		int cnt=0;need.clear();

		for(int i=0;i<n;i++)

		{

			seq1[(mv+i)%n]=A[i]-'0';

			if(psm1[i]-mv<=0&&psm1[i]>=0)

				sm1[(mv+i)%n]=sm2[(mv+i)%n]=0;

			else

				sm1[(mv+i)%n]=psm1[i]-mv,sm2[(mv+i)%n]=psm2[i];

		}

		bool legal=true;

		for(int i=0;i<n;i++)

			if(seq1[i]!=seq2[i]&&sm1[i]<0)

			{

				legal=false;

				break;

			}

		if(legal==false)	continue;

		for(int i=0;i<n;i++)

			if(seq1[i]!=seq2[i])

				cnt++,need.push_back(PII(sm2[i],sm1[i]));

		ans=min(ans,solve()+mv+cnt);

	}

	for(int mv=0;mv<n;mv++)

	{

		int cnt=0;need.clear();

		for(int i=0;i<n;i++)

		{

			seq1[(i-mv+n)%n]=A[i]-'0';

			if(psm2[i]-mv<=0&&psm2[i]>=0)

				sm1[(i-mv+n)%n]=sm2[(i-mv+n)%n]=0;

			else

				sm1[(i-mv+n)%n]=psm1[i],sm2[(i-mv+n)%n]=psm2[i]-mv;

		}

		bool legal=true;

		for(int i=0;i<n;i++)

			if(seq1[i]!=seq2[i]&&sm1[i]<0)

			{

				legal=false;

				break;

			}

		if(legal==false)	continue;

		for(int i=0;i<n;i++)

			if(seq1[i]!=seq2[i])

				cnt++,need.push_back(PII(sm2[i],sm1[i]));

		ans=min(ans,solve()+mv+cnt);

	}

	if(ans!=INF)

		printf("%d\n",ans);

	else

		printf("-1\n");

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 4.810778900455922x):
#include<cstdio>

#include<algorithm>

#include<cstring>

using namespace std;

#define MAXN 2010

#define INF 1000000000

int n,ans=INF;

char a[MAXN],b[MAXN];

int st[MAXN],L[MAXN],R[MAXN];

bool cmpL(int x,int y)

{

	return L[x]<L[y];

}

bool cmpR(int x,int y)

{

	return R[x]<R[y];

}

int main()

{

	scanf("%s%s",a,b);

	n=strlen(a);

	bool f1=0,f2=0;

	for(int i=0;i<n;i++)

	{

		if(a[i]=='1') f1=1;

		if(b[i]=='1') f2=1;

	}

	if(!f2)

	{

		if(!f1) printf("0\n");

		else printf("-1\n");

		return 0;

	}	

	for(int i=0;i<n;i++)

	{

		for(int j=i;b[j]=='0';j=(j-1+n)%n)

			L[i]++;

		for(int j=i;b[j]=='0';j=(j+1)%n)

			R[i]++;

	}

	for(int i=0;i<n;i++)

	{

		int tmp=0,mx=0,r=0;

		for(int j=0,k=i;j<n;k=(k+1)%n,j++)

		{

			if(b[j]==a[k]) continue;

			tmp++;

			if(L[k]>i) st[++r]=k;

		}

		sort(st+1,st+1+r,cmpL);

		for(int j=r;j;j--)

		{

			ans=min(ans,mx*2+i+tmp+(L[st[j]]-i)*2);

			mx=max(mx,R[st[j]]);

		}

		ans=min(ans,mx*2+i+tmp);

		tmp=0,mx=0,r=0;

		for(int j=0,k=(n-i)%n;j<n;k=(k+1)%n,j++)

		{

			if(b[j]==a[k]) continue;

			tmp++;

			if(R[k]>i) st[++r]=k;

		}

		sort(st+1,st+1+r,cmpR);

		for(int j=r;j;j--)

		{

			ans=min(ans,mx*2+i+tmp+(R[st[j]]-i)*2);

			mx=max(mx,L[st[j]]);

		}

		ans=min(ans,mx*2+i+tmp);

	}

	printf("%d\n",ans);

}