#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i)
#define each(a,b) for(auto& (a): (b))
#define all(v) (v).begin(),(v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define cmx(x,y) x=max(x,y)
#define cmn(x,y) x=min(x,y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define sar(a,n) cout<<#a<<":";rep(pachico,n)cout<<" "<<a[pachico];cout<<endl
#define svec(v) cout<<#v<<":";rep(pachico,v.size())cout<<" "<<v[pachico];cout<<endl
#define svecp(v) cout<<#v<<":";each(pachico,v)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl
#define sset(s) cout<<#s<<":";each(pachico,s)cout<<" "<<pachico;cout<<endl
#define smap(m) cout<<#m<<":";each(pachico,m)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int> P;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<P> vp;
typedef vector<string> vs;

const int MAX_N = 2005;

int n;
int l[MAX_N], r[MAX_N];

int solve(vp& id, int w)
{
    int mn = INF;
    vector<int> ch(len(id), -1);
    vector<bool> used(len(id), false);
    multiset<int> st;
    rrep(i,len(id)){
        if(ch[id[i].se] < 0){
            ch[id[i].se] = id[i].fi;
            st.insert(id[i].fi);
        }
    }
    if(len(st) == 0){
        return 0;
    }
    cmn(mn, 2*(2*n-*st.begin()));
    int pos = 0;
    while(pos < len(id)){
        if(!used[id[pos].se]){
            used[id[pos].se] = true;
            st.erase(st.find(ch[id[pos].se]));
        }
        while(pos < len(id)-1 && id[pos].fi == id[pos+1].fi){
            pos++;
            if(!used[id[pos].se]){
                used[id[pos].se] = true;
                st.erase(st.find(ch[id[pos].se]));
            }
        }
        if(len(st) == 0){
            cmn(mn, 2*(id[pos].fi-w));
            return mn;
        }
        cmn(mn, 2*(id[pos].fi-w)+2*(2*n-*st.begin()));
        pos++;
    }
    return mn;
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string a,b;
    cin >> a >> b;
    n = len(a);
    int lo = -1;
    rep(i,n){
        if(b[i] == '1'){
            lo = i;
            break;
        }
    }
    if(lo < 0){
        int mn = INF;
        rep(i,n){
            bool ok = true;
            rep(j,n){
                if(a[(i+j)%n] != b[j]){
                    ok = false;
                    break;
                }
            }
            if(ok){
                cmn(mn, min(i,n-i));
            }
        }
        if(mn < INF){
            cout << mn << "\n";
        }else{
            cout << "-1\n";
        }
        return 0;
    }
    int ro = -1;
    rrep(i,n){
        if(b[i] == '0'){
            r[i] = (lo+n-i)%n;
        }else{
            r[i] = 0;
            lo = i;
            cmx(ro, i);
        }
    }
    rep(i,n){
        if(b[i] == '0'){
            l[i] = (i+n-ro)%n;
        }else{
            l[i] = 0;
            ro = i;
        }
    }
    int ans = INF;
    rep(i,n){
        vp id1,id2;
        int cnt1 = 0, cnt2 = 0;
        int ad = 0;
        rep(j,n){
            if(a[(i+j)%n] != b[j]){
                ad++;
                // if(i == 0){
                    // show(j);
                    // show(l[j]), show(r[j]);
                // }
                int u = (i+l[j])%n, v = (i+n-r[j])%n;
                // if(i == 0){
                    // show(u), show(v);
                // }
                if(u > i && v > i){
                    id1.pb(P(u, cnt1)), id1.pb(P(u+n, cnt1));
                    id1.pb(P(v, cnt1)), id1.pb(P(v+n, cnt1++));
                }
                if(u > 0 && u < i && v < i && v > 0){
                    id2.pb(P(n-u, cnt2)), id2.pb(P(2*n-u, cnt2));
                    id2.pb(P(n-v, cnt2)), id2.pb(P(2*n-v, cnt2++));
                }
            }
        }
        // if(i == 0){
            // svecp(id1), svecp(id2);
        // }
        sort(all(id1)), sort(all(id2));
        int res1 = i+solve(id1, i);
        int res2 = n-i+solve(id2, n-i);
        // show(min(res1, res2) + ad);
        cmn(ans, min(res1, res2) + ad);
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 532