#include <bits/stdc++.h>
#ifdef DEMETRIO
#define deb(...) fprintf(stderr,__VA_ARGS__)
#define deb1(x) cerr << #x << " = " << x << endl
#else
#define deb(...) 0
#define deb1(x) 0
#endif
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define fore(i,a,b) for(int i=a,ThxDem=b;i<ThxDem;++i)
#define SZ(x) ((int)(x).size())
#define mset(a,v) memset(a,v,sizeof(a))
#define mcpy(a,b) memcpy(a,b,sizeof(a))
using namespace std;
typedef long long ll;

char s[2048],t[2048];int n,r;
int a[2048],b[2048];

int doit2(vector<pair<int,int> >& w){
	if(!SZ(w))return 0;
	sort(w.begin(),w.end());
	int k=0,r=1<<30;
	for(int i=SZ(w)-1;i>=0;--i){
		r=min(r,k+w[i].fst);
		k=max(k,w[i].snd);
	}
	r=min(r,k);
	return r;
}

int doit(){
	int rr=(1<<30);
	fore(i,0,n){
		a[i]=b[i]=0;
		if(s[i]=='1'){
			while(t[(i+n-a[i])%n]!='1')a[i]++;
			while(t[(i+b[i])%n]!='1')b[i]++;
		}
	}
	fore(k,0,n){
		int r=k;
		vector<pair<int,int> > w;
		fore(i,0,n){
			r+=s[i]!=t[(i+k)%n];
			if(s[i]=='1'&&t[(i+k)%n]=='0'){
				if(a[i]&&b[i]>k)w.pb(mp(a[i],b[i]-k));
			}
		}
		r+=2*doit2(w);
		rr=min(rr,r);
	}
	return rr;
}

int main(){
	scanf("%s%s",s,t);n=strlen(s);
	bool z=true;
	fore(i,0,n)if(t[i]=='1'){z=false;break;}
	if(z){
		fore(i,0,n)if(s[i]=='1'){z=false;break;}
		puts(z?"0":"-1");
		return 0;
	}
	r=doit();
	reverse(s,s+n);reverse(t,t+n);
	r=min(r,doit());
	printf("%d\n",r);
	return 0;
}