#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_int.hpp>
//typedef boost::multiprecision::cpp_int ll;
typedef long double dd;
//#define i_7 (ll)(1E9+7)
#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E17;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
////////////////////////////
bool comp(l_l a,l_l b){
    return a.second<b.second;
}

ll n;
bool zero(string s){
    rep(i,0,s.size()-1){
        if(s[i]=='1')return false;
    }
    return true;
}
ll check(vector<l_l> v,ll q){
    ll res=inf;
    ll vs=v.size();
    ll maxr[vs];
    sort(v.begin(),v.end());
    for(ll i=vs-1;i>=1;i--){
        if(i==vs-1)maxr[i]=v[i].second;
        else{
            maxr[i]=max(v[i].second,maxr[i+1]);
        }
    }
    
    rep(i,1,vs-1){
        ll sum=v[i-1].first*2+maxr[i];
        ll pos=q+maxr[i];
        if(pos>=n)pos-=n;
        ll idou=min(pos,n-pos);
        Min(res,sum+idou);
    }
    ////////
    sort(v.begin(),v.end(),comp);
    ll maxl[vs];
    for(ll i=vs-1;i>=1;i--){
        if(i==vs-1)maxl[i]=v[i].first;
        else{
            maxl[i]=max(v[i].first,maxl[i+1]);
        }
    }
    rep(i,1,vs-1){
        ll sum=v[i-1].second*2+maxl[i];
        ll pos=q-maxl[i];
        if(pos<0)pos+=n;
        ll idou=min(pos,n-pos);
        Min(res,sum+idou);
    }
    
    return res;
}

int main(){fastio
    string a,b;cin>>a>>b;
    if(zero(b)){
        if(zero(a))cout<<0;
        else cout<<-1;
        return 0;
    }
    n=a.size();
    ll l[n],r[n];
    rep(i,0,n-1){
        ll pos=i;
        ll c=0;
        while(b[pos]=='0'){
            pos--;
            if(pos==-1)pos+=n;
            c++;
        }
        l[i]=c;
    }
    rep(i,0,n-1){
        ll pos=i;
        ll c=0;
        while(b[pos]=='0'){
            pos++;
            if(pos==n)pos-=n;
            c++;
        }
        r[i]=c;
    }
    //rep(i,0,n-1)cout<<l[i]<<" ";cout<<endl;
    //rep(i,0,n-1)cout<<r[i]<<" ";cout<<endl;
    ll ans=inf;
    rep(i,0,n-1){
        vector<ll>chan;
        rep(j,i,i+n-1){
            ll pos=j;
            if(pos>=n)pos-=n;
            if(a[pos]!=b[j-i]){
                chan.pb(pos);
            }
        }
        ll res=chan.size();
        ////////両側移動
        vector<l_l>v;
        for(auto x:chan){
            v.pb(l_l(l[x],r[x]));
        }
        ll rres=res+check(v,i);
        
        Min(ans,rres);
        /////////////////////////片側移動
        ll ls=0,rs=0;
        for(auto x:chan){
            Max(ls,l[x]);
            Max(rs,r[x]);
        }
        ll p=i-ls;
        if(p<0)p+=n;
        ls+=min(p,n-p);
        p=i+rs;
        if(p>=n)p-=n;
        rs+=min(p,n-p);
        //for(auto x:chan)cout<<x<<" ";cout<<endl;
        //cout<<i<<":"<<res<<" "<<ls<<" "<<rs<<endl;
        res+=min(ls,rs);
        Min(ans,res);
        
    }
    cout<<ans<<endl;
    
    return 0;
}



/*
000001100000
000010010000


*/


Measured memory_bytes: 384