#include "bits/stdc++.h"
#define puba push_back
#define ff first
#define ss second
#define bend(_x) begin(_x), end(_x)
#define szof(_x) ((int) (_x).size())
#define TASK_NAME ""

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1e9 + 7;
const ll INFL = 1e18 + 123;
const double PI = atan2(0, -1);

mt19937 tw(960172);
ll rnd(ll x, ll y) { static uniform_int_distribution<ll> d; return d(tw) % (y - x + 1) + x; }

const int MAXN = 2005;
char buf[MAXN];
int a[MAXN], b[MAXN];


int main() {
    //freopen(TASK_NAME ".in", "r", stdin);
    //freopen(TASK_NAME ".out", "w", stdout);
    cerr << fixed << setprecision(15);
    cout << fixed << setprecision(15);
    
    scanf("%s", buf);
    int n = strlen(buf);

    for (int i = 0; i < n; ++i) {
        a[i] = buf[i] - '0';
    }

    scanf("%s", buf);
    for (int i = 0; i < n; ++i) {
        b[i] = buf[i] - '0';
    }

    if (*max_element(b, b + n) == 0) {
        if (*max_element(a, a + n) == 1) {
            cout << "-1\n";
        } else {
            cout << "0\n";
        }
        return 0;
    }
    
    vector<pii> lr(n);
    for (int i = 0; i < n; ++i) {
        if (!a[i]) {
            continue;
        }
        int pos = i;
        int c = 0;
        while (!b[pos]) {
            pos = (pos + 1) % n;
            ++c;
        }
        lr[i].ss = c;
        pos = i;
        c = 0;
        while (!b[pos]) {
            pos = (pos + n - 1) % n;
            ++c;
        }
        lr[i].ff = c;
    }

    
    int ans = INF;
    for (int i = 0; i < n; ++i) {
        ll now = 0;
        vector<pii> need;
        for (int j = 0; j < n; ++j) {
            if (a[j] != b[(j + i) % n]) {
                ++now;
            }
            if (a[j] && !b[(j + i) % n]) {
                need.puba(lr[j]);
            }
        }

        /*
        cerr << "i: " << i << endl;
        for (pii p : need) {
            cerr << p.ff << " " << p.ss << endl;
        }
        */
        int l = 0;
        sort(bend(need), [](pii p1, pii p2) { return p1.ss > p2.ss; });

        int tmp;
        int shift = (n - i) % n;
        for (auto p : need) {
            tmp = now + p.ss * 2;
            if (l > shift) {
                tmp += l + l - shift;
            } else {
                tmp += shift;
            }
            ans = min(ans, tmp);
            l = max(l, p.ff);
        }

        tmp = now;
        if (l > shift) {
            tmp += l + l - shift;
        } else {
            tmp += shift;
        }
        ans = min(ans, tmp);

        sort(bend(need), [](pii p1, pii p2) { return p1.ff > p2.ff; });

        shift = i;
        int r = 0;
        for (auto p : need) {
            tmp = now + p.ff * 2;
            if (r > shift) {
                tmp += r + r - shift;
            } else {
                tmp += shift;
            }
            ans = min(ans, tmp);
            r = max(r, p.ss);
        }

        tmp = now;
        if (r > shift) {
            tmp += r + r - shift;
        } else {
            tmp += shift;
        }

        ans = min(ans, tmp);
        //cerr << ans << endl;
    }

    cout << ans << "\n";

    #ifdef LOCAL
        cerr << "time: " << clock() << endl;
    #endif
    return 0;
}                              

Measured memory_bytes: 256