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

typedef long long int ll;
typedef long double ld;

#define rep(i,a,b) for(ll i=a;i<=b;++i)
#define rev(i,a,b) for(ll i=a;i>=b;i--)
#define pll pair<ll,ll>
#define vll vector<ll>
#define sll set<ll>
#define vpll vector<pll>
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define ln length()
#define M 1000000007

string s1,s2;
ll req[10001],lt[10001],rt[10001];

ll n;

ll mindis(ll x,ll y){
    if(x>y) swap(x,y);
    return min(y-x,n-(y-x));
}

int main(){
    ios::sync_with_stdio(false);cin.tie(0);

    cin>>s1>>s2;
    n=s1.size();

    ll ct1=0;
    for(char c:s2) if(c == '1') ct1++;
    if(ct1 == 0){
        for(char c:s1) if(c == '1'){
            cout<<-1<<'\n';
            return 0;
        }
        cout<<0<<'\n';
        return 0;
    }
    if(n == 1){
        if(s1 == s2) cout<<0<<'\n';
        else cout<<1<<'\n';
        return 0;
    }
    rep(i,0,n-1){
        ll st=i;
        while(st>=0 && s2[st] == '0') st--;
        if(st>=0) lt[i]=st;
        else{
            st=n-1;
            while(s2[st]!='1') st--;
            lt[i]=st;
        }
        st=i;
        while(st<n && s2[st] == '0') st++;
        if(st!=n) rt[i]=st;
        else{
            st=0;
            while(s2[st]!='1') st++;
            rt[i]=st;
        }
    }

    ll ans=1e15;
    rep(st,0,n-1){
        rep(i,0,n-1){
            req[i]=0;
            if(i<st && s2[n-st+i]!=s1[i]) req[i]=1;
            if(i>=st && s2[i-st]!=s1[i]) req[i]=1;
        }

        ll rqct=0;
        multiset<ll> rtcl;
        rep(i,0,n-1) if(req[i]) {
            rqct++;
            if(rt[i]>=i) rtcl.insert(rt[i]-i);
            else rtcl.insert(rt[i]+n-i);
        }
        vpll srt;
        rep(i,0,n-1) if(req[i]){
            if(lt[i]<=i) srt.pb(mp(i-lt[i],i));
            else srt.pb(mp(i+n-lt[i],i));
        }

        sort(srt.begin(),srt.end());
        reverse(srt.begin(),srt.end());

        rep(shl,0,n-1){
            while(!srt.empty() && srt.back().F <= shl){
                if(rt[srt.back().S] >= srt.back().S) rtcl.erase(rtcl.find(rt[srt.back().S] - srt.back().S));
                else rtcl.erase(rtcl.find(rt[srt.back().S] + n - srt.back().S));
                srt.pop_back();
            }
            if(rtcl.empty()) ans=min(ans,shl+rqct+mindis(shl,st));
            else{
                auto it=rtcl.end();it--;
                ans=min(ans,2*shl+rqct+*it+mindis(n-*it,st));
            }
        }


        multiset<ll> ltcl;
        rep(i,0,n-1) if(req[i]) {

            if(lt[i]<=i) ltcl.insert(i-lt[i]);
            else ltcl.insert(n-lt[i]+i);
        }
        srt.clear();
        rep(i,0,n-1) if(req[i]){
            if(rt[i]>=i) srt.pb(mp(rt[i]-i,i));
            else srt.pb(mp(rt[i]+n-i,i));
        }

        sort(srt.begin(),srt.end());
        reverse(srt.begin(),srt.end());

        rep(shr,0,n-1){
            while(!srt.empty() && srt.back().F <= shr){
                if(lt[srt.back().S] <= srt.back().S) ltcl.erase(ltcl.find(srt.back().S - lt[srt.back().S]));
                else ltcl.erase(ltcl.find(n - lt[srt.back().S] + srt.back().S));
                srt.pop_back();
            }
            if(ltcl.empty()) ans=min(ans,shr+rqct+mindis(n-shr,st));
            else{
                auto it=ltcl.end();it--;
                ans=min(ans,2*shr+rqct+*it+mindis(*it,st));
            }
        }
    }
    cout<<ans<<'\n';

}


Measured memory_bytes: 544