#include <bits/stdc++.h>

using namespace std;
typedef long long LL;
#define rep(i, l, r) for (int i = l; i<r;i++)
#define print(arr, r, c) rep(i, 0, r) {rep(j, 0, c)cout<<arr[i][j]<<"";cout<<endl;}
#define all(b) b.begin() , b.end()
#define mp(a, b) make_pair(a,b)
#define pb(a) push_back(a)
#define vi vector<int>
#define vd vector<double>
#define vs vector<string>
#define vii vector<pair<int,int>>
#define vvi vector<vector<int>>
#define ii pair<int,int>
#define turnOff(k, i) (k&(~(1<<(i-1))))
#define isOn(k, i) (k&&(1<<i-1)?true:false)
#define pll pair<long long int , long long int>
#define ull unsigned long long int
#define ll  long long int
#define add(a, b) ((a+b)%MOD)
#define sub(a, b) ((a-b+MOD)%MOD)
#define mul(a, b) ((1ll*a*b)%MOD)
#ifdef  DEBUG
#define MAXN 203
#else
#define MAXN 402
#endif
#define MAXLG 20
#define endl '\n'
#define PI 3.141592653589793238
#define MOD (1000000007)
#define INF (2000000000)
#define EPS (0.00000001)
#define treap treapNode

typedef vector<int> VI;
typedef pair<int,int> PII;
typedef vector<PII> VPII;


VI LongestIncreasingSubsequence(VI v) {
    VPII best;
    VI dad(v.size(), -1);

    for (int i = 0; i < v.size(); i++) {
#ifdef STRICTLY_INCREASNG
        PII item = make_pair(v[i], 0);
        VPII::iterator it = lower_bound(best.begin(), best.end(), item);
        item.second = i;
#else
        PII item = make_pair(v[i], i);
    VPII::iterator it = upper_bound(best.begin(), best.end(), item);
#endif
        if (it == best.end()) {
            dad[i] = (best.size() == 0 ? -1 : best.back().second);
            best.push_back(item);
        } else {
            dad[i] = dad[it->second];
            *it = item;
        }
    }

    VI ret;
    for (int i = best.back().second; i >= 0; i = dad[i])
        ret.push_back(v[i]);
    reverse(ret.begin(), ret.end());
    return ret;
}



int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
#ifdef DEBUG
    freopen("input", "r", stdin);
#endif
     string a,b;
    cin>>a>>b;
    bool allZ = true,aZ=true;
    rep (i,0,b.size()) {
        if (b[i]=='1')allZ=false;
        if (a[i]=='1')aZ=false;
    }


    if (allZ && !aZ) {
        cout<<"-1";
        return 0;
    }





    int n = b.size();
    int left[b.size()],right[b.size()];
    rep (i,0,b.size()) {
        //go left
        int l=i,r=i;
        int lc=0,rc=0;
        do {
            if (b[l]=='1') {
                left[i] = lc;
                break;
            }
            lc--;
            l = (l-1 +n)%n;
        }while(l!=i);
        //go right
        do {
            if (b[r]=='1') {
                right[i] = rc;
                break;
            }
            rc++;
            r = (r+1 +n)%n;
        }while(r!=i);
    }

    int ans = INF;

    for (int d= n;d >= -n;d--) {
        vii temp;
        int flips=0;
        rep (i,0,a.size()) {
            if (a[i] != b[(i+d+n)%n]) {
                if (d>=0) {
                    if (right[i]>d) {
                        temp.pb(mp(left[i],right[(i+d+n)%n]));
                    }
                } else {
                    if (left[i]<d) {
                        temp.pb(mp(left[(i+d+n)%n],right[(i)%n]));
                    }
                }
            flips++;

            }
        }
        sort(all(temp));
        int l,r=0;
        int LR = temp.size()==0?0:INF;
        rep (i,0,temp.size()) {
            l = temp[i].first;
            LR = min(2*(r-l),LR);
            r = max(r,temp[i].second);
        }
        LR = min(2*(r),LR);
        ans = min(ans,LR+flips+abs(d));
     }
    cout<<ans;


    return 0;
}


Measured memory_bytes: 256