// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>
 
#define N (ll)(1e6+3)
#define INF (ll)(1e18+3)
#define MOD (ll)(1e9+7)
 
#define ll long long
#define rep(i,a,n) for(ll i = a; i < n; i++)
#define per(i,a,n) for(ll i = n-1; i >= a; i--)
 
//using namespace __gnu_pbds;
using namespace std;
 
// typedef
// tree<
//     pair<ll,ll>,
//     null_type,
//     less<pair<ll,ll>>,
//     rb_tree_tag,
//     tree_order_statistics_node_update>
// ordered_set;

void solve() {
    string a, b;
    cin >> a >> b;
    ll n = a.size();
    vector<bool> va(n), vb(n);
    vector<ll> left(n), right(n);
    ll sa = 0, sb = 0;
    rep(i,0,n) {
        va[i] = a[i]=='1';
        vb[i] = b[i]=='1';
        sa += va[i];
        sb += vb[i];
    }
    if (!sb && sa) {
        cout << -1 << endl;
        return;
    }

    rep(i,0,n) {
        rep(j,0,n) {
            ll r = (i+j)%n;
            if (vb[r]) {
                right[i] = j;
                break;
            }
        }
        rep(j,0,n) {
            ll l = (i-j+n)%n;
            if (vb[l]) {
                left[i] = j;
                break;
            }
        }
    }

    ll ans = INF;
    rep(i,0,n) {
        vector<bool> v(n);
        ll mnCost = INF;
        {
            //rotate left
            ll cost = i;
            vector<pair<ll,ll> > vp;
            multiset<ll,greater<ll> > ms;
            rep(j,0,n) {
                ll ind = (j+i)%n;
                v[j] = va[ind];
                if (v[j] != vb[j]) {
                    vp.push_back({max(0LL,left[ind]-cost),right[ind]});
                }
            }
            cost += vp.size();
            sort(vp.begin(), vp.end());
            reverse(vp.begin(), vp.end());
            ll mn = INF;
            rep(j,0,vp.size()+1) {
                ll cur = 0, cur2 = 0;
                if (j < vp.size())
                    cur = vp[j].first;
                if (!ms.empty())
                    cur2 = *ms.begin();
                if (j < vp.size())
                    ms.insert(vp[j].second);
                mn = min(mn, cur+cur2);
            }
            cost += 2*mn;
            mnCost = min(cost, mnCost);
        }
        {
            //rotate right
            ll cost = (n-i)%n;
            vector<pair<ll,ll> > vp;
            multiset<ll,greater<ll> > ms;
            rep(j,0,n) {
                ll ind = (j+i)%n;
                v[j] = va[ind];
                if (v[j] != vb[j]) {
                    vp.push_back({left[ind],max(0LL,right[ind]-cost)});
                }
            }
            cost += vp.size();
            sort(vp.begin(), vp.end());
            reverse(vp.begin(), vp.end());
            ll mn = INF;
            rep(j,0,vp.size()+1) {
                ll cur = 0, cur2 = 0;
                if (j < vp.size())
                    cur = vp[j].first;
                if (!ms.empty())
                    cur2 = *ms.begin();
                if (j < vp.size())
                    ms.insert(vp[j].second);
                mn = min(mn, cur+cur2);
            }
            cost += 2*mn;
            mnCost = min(cost, mnCost);
        }
        ans = min(ans,mnCost);
    }

    cout << ans << endl;
}
 
int main() {
    solve();
}

Measured memory_bytes: 384