#include<bits/stdc++.h> 
#define fo(i,a,b) for(i=a;i<=b;i++)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define min(a,b) (a<b?a:b)
#define max(a,b) (a>b?a:b)
typedef long long ll;
using namespace std;
inline int read(){
	int n=0,f=1;char c;
	for(c=getchar();(c<'0'||c>'9')&&c!='-';c=getchar());
	if (c=='-') c=getchar(),f=-1;
	for(;c>='0'&&c<='9';c=getchar()) n=n*10+c-48;
	return n*f;
}
const int maxn=2e3+5;
char A[maxn],B[maxn];
struct ar{
	int l,r,id;
}w[maxn];
int i,j,t,n,s,mx,mi,now,ans,cnt;
bool cmp(ar a,ar b){
	return (a.r==b.r)?a.l<b.l:a.r<b.r; 
} 
bool bz[maxn];
int main(){
	scanf("%s%s",&A,&B);
	n=strlen(A);
	fo(i,0,n-1) if (B[i]=='1') break;
	if (i==n){
		fo(i,0,n-1) if (A[i]=='1') return puts("-1"),0;
		return puts("0"),0;
	}
	fo(i,0,n-1){
		for(j=i,t=0;B[j]!='1';j=(j==n-1)?0:j+1,t++);
		w[i+1].r=t;
		for(j=i,t=0;B[j]!='1';j=(j==0)?n-1:j-1,t--);
		w[i+1].l=t,w[i+1].id=i;
	}
	sort(w+1,w+1+n,cmp);
	ans=1e9;
	fo(s,-n+1,n-1){
		memset(bz,0,sizeof(bz));
		cnt=0;
		fo(i,0,n-1) cnt+=(bz[i]=A[i]!=B[(i+s+n)%n]);
		mi=min(s,0),now=n;
		int S=abs(s);
		fd(mx,n-1,max(0,s)){
			for(;now&&w[now].r>mx;now--)if (bz[w[now].id]) mi=min(mi,w[now].l);
			ans=min(ans,2*(mx-mi)-S+cnt);
		}
	}
	printf("%d\n",ans);
}