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

#pragma GCC optimize("O2,no-stack-protector,unroll-loops,fast-math")

#define F first
#define S second
#define pb push_back
#define SZ(x) (ll)(x.size())
#define all(x) x.begin(),x.end()
#define MP make_pair

typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const ll maxn=2e3+10, maxm=5e4+10, lg=21, mod=1e9+7, inf=1e18;

string s,t;
ll n,L[3*maxn],R[3*maxn];

int main(){
	ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	
	memset(L,69,sizeof(L)),memset(R,69,sizeof(R));
	cin>>s>>t; n=SZ(s);
	t=t+t+t;
	for(int i=0;i<3*n;i++) L[i]=(t[i]=='1' ? 0:L[i-1]+1);
	for(int i=3*n-1;i>=0;i--) R[i]=(t[i]=='1' ? 0:R[i+1]+1);
	if(R[0]>=inf){
		for(int i=0;i<n;i++)if(s[i]=='1') return cout<<-1,0;
		return cout<<0,0;
	}
	ll ans=inf;
	for(int d=-n;d<=n;d++){
		vector<pll> bb;
		ll ek=0; for(int i=n;i<2*n;i++)if(s[i-n]!=t[i+d]) bb.pb({max(L[i]+min(d,0),0ll),max(R[i]-max(d,0),0ll)}), ek++;
		sort(all(bb));
		ll mx=0; for(int i=SZ(bb)-1;i>=0;i--){
			ans=min(ans,ek+2*(bb[i].F+mx)+abs(d));
			mx=max(mx,bb[i].S);
		}
		ans=min(ans,ek+2*mx+abs(d));
	}
	cout<<ans;
	
	return 0;
}



 
