#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

#define each(i,a) for (auto&& i : a)
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
#define pb push_back
#define all(a) (a).begin(),(a).end()
#define chmin(x,v) x = min(x, v)
#define chmax(x,v) x = max(x, v)

const ll linf = 1e18;
const int inf = 1e9;
const double eps = 1e-12;
const double pi = acos(-1);

template<typename T>
istream& operator>>(istream& is, vector<T>& vec) {
    each(x,vec) is >> x;
    return is;
}
template<typename T>
ostream& operator<<(ostream& os, const vector<T>& vec) {
    rep(i,vec.size()) {
        if (i) os << " ";
        os << vec[i];
    }
    return os;
}
template<typename T>
ostream& operator<<(ostream& os, const vector< vector<T> >& vec) {
    rep(i,vec.size()) {
        if (i) os << endl;
        os << vec[i];
    }
    return os;
}

// SegmentTree<int> seg(n, 0x7FFFFFFF, [](int a, int b){return min(a, b);});
template <class T>
class SegmentTree {
    using func_t = function<T(T, T)>;
    const int sz, n;
    const T id;
    func_t merge;
    vector<T> data;
    int expand(int n) const { return n == 1 ? n : expand((n + 1) / 2) * 2; }
public:
    SegmentTree(const vector<T> &init, T id, func_t merge) :
        sz(init.size()), n(expand(sz)), id(id), data(n * 2, id), merge(merge) {
        copy(begin(init), end(init), begin(data)+n);
        RREP(i, n) {
            data[i] = merge(data[i * 2 + 0], data[i * 2 + 1]);
        }
    }
    int size() const { return sz; }
    void update(int p, T val) {
        assert (0 <= p && p < sz);
        data[p += n] = val;
        while (p /= 2) data[p] = merge(data[p * 2], data[p * 2 + 1]);
    }
    T find(int l, int r) const {
        assert (0 <= l && l <= r && r <= sz);
        l += n; r += n;
        T res1 = id, res2 = id;
        while (l != r) {
            if (l % 2) res1 = merge(res1, data[l++]);
            if (r % 2) res2 = merge(data[--r], res2);
            l /= 2; r /= 2;
        }
        return merge(res1, res2);
    }
};

ll solve(const string& A, const string& B) {
    const ll n = A.size();
    vector<ll> bv(n);
    rep(i, n) bv[i] = B[i] == '1';
    auto dist = [&](ll l, ll r) {
        if (l <= r) return r - l;
        return n + r - l;
    };
    auto is_in = [&](ll x, ll l, ll r) {
        if (r - l >= n) return true;
        l %= n;
        r %= n;
        x %= n;
        if (l <= r) return l <= x && x < r;
        return x < r || l <= x;
    };
    bool a0 = true, b0 = true;
    rep(i, n) if (A[i] == '1') a0 = false;
    rep(i, n) if (B[i] == '1') b0 = false;
    if (b0) {
        if (a0) throw 0;
        else throw -1;
    }
    vector<ll> L(n, -linf), R(n, linf);
    rep(i, n) if (bv[i]) L[i] = R[i] = i;
    rep(t, 3) {
        rep(i, n) {
            ll bi = (i+n-1)%n;
            if ( dist(L[bi], i) < dist(L[i], i) ) {
                L[i] = L[bi];
            }
        }
        rrep(i, n) {
            ll ni = (i+1)%n;
            if ( dist(i, R[ni]) < dist(i, R[i]) ) {
                R[i] = R[ni];
            }
        }
    }
    rep(i, n) assert(L[i] != -linf);
    rep(i, n) assert(R[i] != linf);
    ll ans = linf;
    rep(pos, 2*n+1) {
        // 最初に左に行く
        ll a = 0;
        SegmentTree<ll> seg(vector<ll>(n, 0), 0, [](ll a, ll b) { return max(a, b); });
        vector<vector<ll>> ev(n+1);
        rep(i, n) {
            if (A[i] == B[(i+pos)%n]) continue;
            ++a;
            if (dist(i, R[i]) <= pos) continue;
            // if (is_in(R[i], i, i+pos+1)) continue;
            assert(pos < n);
            seg.update(i, dist(L[i], i));
            ev[dist(i, R[i])-pos].pb(i);
        }
        a += pos;
        rep(i, n+1) {
            each(j, ev[i]) {
                seg.update(j, 0);
            }
            // if (i < 3) {
            //     cout << i << " " << a << " " << seg.find(0, n) << " " << i << endl;
            // }
            chmin(ans, a + seg.find(0, n)*2 + i*2);
        }
        // cout << a << " " << left << " " << pos << endl;
        // // 最初に右に行く
        // {
        //     ll a = 0, right = 0;
        //     rep(i, n) {
        //         if (A[i] == B[(i+pos)%n]) continue;
        //         ++a;
        //         if (is_in(L[i], i-pos, i)) continue;
        //         chmax(right, dist(i, R[i]));
        //     }
        //     a += 2 * right + (n - pos);
        //     chmin(ans, a);
        // }
    }
    assert(ans >= 0);
    assert(ans < linf);
    // if (ans >= linf) ans = -1;
    return ans;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    string A, B; cin >> A >> B;
    try {
        ll ans = solve(A, B);
        reverse(all(A));
        reverse(all(B));
        chmin(ans, solve(A, B));
        cout << ans << endl;
    }
    catch (int ans) {
        cout << ans << endl;
    }
}


Measured memory_bytes: 516