#include <algorithm>
#include <cassert>
#include <queue>
#include <vector>
#include <iostream>
using namespace std;

const int INF = 1<<30;

int parse(string &s) {
    int result = 0;
    for (char c : s) result = result * 2 + (c % 2);
    return result;
}

int bruteforce(string S, string T) {
    const int n = S.size(), s = parse(S), t = parse(T);
    if (t == 0) return s == 0 ? 0 : -1;

    int dp[1<<n];
    fill(dp, dp + (1<<n), INF);
    dp[s] = 0;
    queue<int> q;
    q.push(s);
    auto rotate_r = [n](int u) {
        const int b = u & 1;
        return (u >> 1) | (b << (n - 1));
    };
    auto rotate_l = [n](int u) {
        const int b = (u >> (n - 1)) & 1;
        return ((u << 1) ^ (b << n)) | b;
    };
    while (!q.empty()) {
        auto u = q.front();
        q.pop();
        if (const int v = rotate_r(u); dp[v] == INF) {
            dp[v] = dp[u] + 1;
            q.push(v);
        }
        if (const int v = rotate_l(u); dp[v] == INF) {
            dp[v] = dp[u] + 1;
            q.push(v);
        }
        for (int i = 0; i < n; i++) {
            if ((t >> i) & 1) {
                if (const int v = u ^ (1 << i); dp[v] == INF) {
                    dp[v] = dp[u] + 1;
                    q.push(v);
                }
            }
        }
    }

    return dp[t];
}

int solve(string &s, string &t) {
    const int n = s.size();
    int ans = INF;
    int left[n], right[n];
    int l = [n, t]() {
        for (int i = n-1; i >= 0; i--) if (t[i] == '1') return i - n;
        return 0;
    }();
    assert(l < 0);
    for (int i = 0; i < n; i++) {
        if (t[i] == '1') l = i; 
        left[i] = i - l;
    }
    int r = [n, t]() {
        for (int i = 0; i < n; i++) if (t[i] == '1') return i + n;
        return 0;
    }();
    assert(r >= n);
    for (int i = n-1; i >= 0; i--) {
        if (t[i] == '1') r = i;
        right[i] = r - i;
    }

    // for (int i = 0; i < n; i++) cerr << i << " " << left[i] << " " << right[i] << endl;
    // cerr << endl;
    vector<int> lr[n];
    for (int r = 0; r < n; r++) {
        int diff = 0;
        for (int i = 0; i < n; i++)
            if (s[i] != t[(i + r) % n])
                diff++;
        if (diff + r >= ans) continue;

        for (vector<int> &v : lr) v.clear();
        for (int i = 0; i < n; i++) {
            if (s[i] != t[(i + r) % n]) {
                lr[left[i]].push_back(right[i]);
            }
        }
        int rr[n];
        rr[n-1] = 0;
        for (int l = n-1; l > 0; l--) {
            rr[l-1] = rr[l];
            for (int s : lr[l]) rr[l-1] = max(rr[l-1], s);
        }
        for (int l = 0; l < n; l++) {
            if (diff + 2 * l + r >= ans) continue;
            int roffset = max(0, rr[l] - r);
            // cerr << l << " " << r << " " << rr << " " << diff + 2 * l + r + 2 * roffset << endl;
            ans = min(ans, diff + 2 * l + r + 2 * roffset);
        }
    }
    return ans;
}

int main() {
    string s, t; cin >> s >> t;
    if (s == t) { cout << "0\n"; return 0; }
    if (t.find('1') == string::npos) { cout << "-1\n"; return 0; }

    int ans = solve(s, t);
    reverse(s.begin(), s.end());
    reverse(t.begin(), t.end());
    ans = min(ans, solve(s, t));
    cout << ans << endl;

    // check
    // const int expect = bruteforce(s, t);
    // if (ans != expect) {
    //     cerr << "expect " << expect << ", got " << ans << " on test" << endl;
    //     reverse(s.begin(), s.end());
    //     reverse(t.begin(), t.end());
    //     cerr << s << endl << t << endl;
    //     exit(1);
    // }

    // constexpr int n = 8;
    // for (int a = 0; a < 1<<n; a++)
    //     for (int b = 1; b < 1<<n; b++) {
    //         if (a == 0 || a == b) continue;
    //         s.resize(n);
    //         t.resize(n);
    //         for (int i = 0; i < n; i++) {
    //             s[i] = ((a >> i) & 1) ? '1' : '0';
    //             t[i] = ((b >> i) & 1) ? '1' : '0';
    //         }
    //         int ans = solve(s, t);
    //         reverse(s.begin(), s.end());
    //         reverse(t.begin(), t.end());
    //         ans = min(ans, solve(s, t));
    //         int expect = bruteforce(s, t);
    //         if (ans != expect) cerr << s << " " << t << " " << ans << " " << expect << endl;
    //     }
}


Measured memory_bytes: 3268