#include<bits/stdc++.h>
using namespace std;
#define nn 2008
char a[nn],b[nn];int n;
int tol[nn],tor[nn];

int ans=1e9;

int faq[nn];
void chkmax(int &x,int y) {x=max(x,y);}
void solve()
{
		
	for(int i=0;i<n;i++)
	{
		tol[i]=tor[i]=0;
		for(int j=0;j<=n;j++,tol[i]=j)
			if(b[(i-j+n)%n]-'0') break;
			
		for(int j=0;j<=n;j++,tor[i]=j)
			if(b[(i+j)%n]-'0') break;
		
	}
	
	for(int x=0;x<n;x++)
	{
		memset(faq,0,sizeof faq);int chg=0;
		for(int i=0;i<n;i++)
			if(b[(i+x)%n]!=a[i]) 
			{
				if(tol[i]>=n) chg=1e9;
				chkmax(faq[tol[i]],tor[i]),chg++;
			}
		
		int ss=x;	
		for(int l=n-1;l>=0;l--)
		{
			chkmax(ss,faq[l+1]);
			ans=min(ans,ss*2-x+l*2  +chg);
		}
		
	}
	
}

int main()
{
	scanf("%s%s",a,b);n=strlen(a);
	
	solve();
	
	reverse(a,a+n);reverse(b,b+n);
	solve();
	
	if(ans>1e8) ans=-1;
	printf("%d\n",ans);
	return 0;
}