#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = (int)1.01e9;
const int N = 1 << 18;

const int C = (int)1e8;

int solve1(string a, string b) {
    if (b.find('1') == -1 && a.find('1') != -1) {
        return INF;
    }
    if (a == b) return 0;

    int n = a.length();
    vector<int> nxt(n);
    vector<int> prv(n);
    for (int i = 0; i < n; i++) {
        while (b[(i + nxt[i]) % n] == '0') nxt[i]++;
        while (b[(i - prv[i] + n) % n] == '0') prv[i]++;
    }
    int cans = INF;

    // first some left (i -> i+1)
    // then some right (i -> i-1)
    // add is i -> i+add
    // add is +left-right
    for (int add = -n; add <= n; add++) {
        int mx = 0;
        int need = 0;
        vector<pair<int, int> > vct;
        for (int i = 0; i < n; i++) {
            if (a[i] != b[(i + add + n) % n]) {
                bool ok = 1;
                if (add >= 0) ok = nxt[i] <= add;
                else ok = prv[i] <= -add;

                if (!ok) {
                    //mx = max(mx, nxt[i]);
                    int d1, d2;
                    if (add >= 0) {
                        d1 = nxt[(i + add + n) % n];
                        d2 = prv[i];
                    } else {
                        d1 = nxt[i];
                        d2 = prv[(i + add + n) % n];
                    }
                    vct.push_back({d1, d2});
                }
                need++;
            }
        }
        sort(vct.begin(), vct.end());

        vector<int> suf(vct.size() + 1);
        for (int i = (int)vct.size() - 1; i >= 0; i--) {
            suf[i] = max(suf[i + 1], vct[i].second);
        }

        int cur = INF;
        for (int i = 0; i <= (int)vct.size(); i++) {
            int left = i ? vct[i - 1].first : 0;
            cur = min(cur, abs(add) + 2 * (left + suf[i]));
        }
        cur += need;

        /*int cur;
        if (add >= 0) cur = 2 * max(0, mx - add) + add;
        else cur = 2 * mx - add;
        cur += need;*/

        cans = min(cans, cur);
    }
    return cans;
}

int solve(string a, string b) {
    int ans = solve1(a, b);
    /*reverse(a.begin(), a.end());
    reverse(b.begin(), b.end());
    ans = min(ans, solve1(a, b));*/
    if (ans == INF) ans = -1;
    return ans;
}

int slow(string a, string b) {
    int n = a.length();
    map<string, int> mp;
    queue<string> q;
    mp[a] = 0;
    q.push(a);
    while (!q.empty()) {
        string s = q.front();
        q.pop();

        string t;

        t = s;
        rotate(t.begin(), t.begin() + 1, t.end());
        if (!mp.count(t)) {
            mp[t] = mp[s] + 1;
            q.push(t);
        }

        t = s;
        rotate(t.begin(), t.begin() + (n - 1), t.end());
        if (!mp.count(t)) {
            mp[t] = mp[s] + 1;
            q.push(t);
        }

        for (int i = 0; i < n; i++) if (b[i] == '1') {
            t = s;
            t[i] = (t[i] == '0' ? '1' : '0');
            if (!mp.count(t)) {
                mp[t] = mp[s] + 1;
                q.push(t);
            }
        }
    }
    if (!mp.count(b)) return -1;
    return mp[b];
}

void stress() {
    for (int it = 38386;; it++) {
        srand(it);
        cerr << it << endl;

        int n = rand() % 10 + 1;
        string a = "", b = "";
        for (int i = 0; i < n; i++) {
            a += (char)('0' + rand() % 2);
            b += (char)('0' + rand() % 2);
        }
        int ans1 = solve(a, b);
        int ans2 = slow(a, b);
        if (ans1 != ans2) {
            cout << ans1 << " instead of " << ans2 << endl;
            cout << a << endl << b << endl;
            exit(0);
        }
    }
}

int main() {
#ifdef HOME
    freopen("in", "r", stdin);
#endif
    //stress();

    string a, b;
    while (cin >> a >> b) {
        cout << solve(a, b) << endl;
    }

#ifdef HOME
    cerr << clock() / (double)CLOCKS_PER_SEC << endl;
#endif
    return 0;
}


Measured memory_bytes: 256