#include<bits/stdc++.h>
using namespace std;

int l[2000],r[2000];

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	string A,B;
	cin>>A>>B;
	int ca=0,cb=0,n=A.size();
	for(char c:A)
		if(c=='1')
			ca++;
	for(char c:B)
		if(c=='1')
			cb++;
	if(cb==0){
		if(ca==0)	cout<<0<<endl;
		else	cout<<-1<<endl;
		return 0;
	}
	for(int i=0;i<n;i++){
		for(l[i]=0;;l[i]++){
			int cur = i-l[i];
			if(cur<0)	cur+=n;
			if(B[cur]=='1')
				break;
		}
		for(r[i]=0;;r[i]++){
			int cur = i+r[i];
			if(cur>=n)	cur-=n;
			if(B[cur]=='1')
				break;
		}
	}
	int ans = 1e9;
	for(int d=-n;d<=n;d++){
		vector<pair<int,int> > v;
		int cnt = 0;
		for(int i=0;i<n;i++){
			int idx = i + d;
			if(idx<0)	idx+=n;
			if(idx>=n)	idx-=n;
			if(A[i]!=B[idx]){
				cnt++;
				if(d<0){
					if(l[i]>-d)
						v.emplace_back(l[i],r[i]);
				}
				else if(d>0){
					if(r[i]>d)
						v.emplace_back(l[i],r[i]);
				}
				else if(l[i]!=0){
					v.emplace_back(l[i],r[i]);
				}
			}
		}
		sort(v.rbegin(),v.rend());
		int mxr = 0, mxl = 0;
		if(d < 0)	mxl = max(mxl,-d);
		else	mxr = max(mxr,d);
		for(auto it:v){
			ans = min(ans,cnt+2*(mxr+it.first)-abs(d));
			mxr=max(mxr,it.second);
			mxl=max(mxl,it.first);
		}
		ans = min(ans,cnt+2*(mxr+(d<0?-d:0))-abs(d));
	}
	cout<<ans<<endl;
}
