#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;

const int INF = (int) 1e9 + 123;
const ll LINF = (ll) 1e18 + 123;
const ld EPS = (ld) 1e-12;
const ll MOD = (ll) 1e9 + 7;

#define sz(x) (int) (x).size()
#define mp(x, y) make_pair(x, y)
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define lb(s, t, x) (int) (lower_bound(s, t, x) - s)
#define ub(s, t, x) (int) (upper_bound(s, t, x) - s)
#define rep(i, f, t) for (auto i = f; i < t; i++)
#define per(i, f, t) for (auto i = f; i >= t; i--)

ll power(ll x, ll y, ll mod = MOD) {
    if (y == 0) {
        return 1;
    }
    if (y & 1) {
        return power(x, y - 1, mod) * x % mod;
    } else {
        ll tmp = power(x, y / 2, mod);
        return tmp * tmp % mod;
    }
}

inline void add(ll &x, ll y, ll mod = MOD) {
    x += y;
    if (x >= mod) x -= mod;
    if (x < 0) x += mod;
}

inline ll sum(ll x, ll y, ll mod = MOD) {
    add(x, y, mod);
    return x;
}

inline ll mult(ll x, ll y, ll mod = MOD) {
    return (x * y) % mod;
}

inline ll div(ll x, ll y, ll mod) {
    return x * power(y, mod - 2, mod);
}

template<typename A, typename B> inline bool mini(A &x, const B &y) {
    if (y < x) {
        x = y;
        return true;
    }
    return false;
}

template<typename A, typename B> inline bool maxi(A &x, const B &y) {
    if (y > x) {
        x = y;
        return true;
    }
    return false;
}

template<typename T> inline void read(T first, T last) {
    while (first != last) {
        cin >> *(first++);
    }
}

template<typename T> inline void print(T first, T last) {
    while (first != last) {
        cout << *(first++) << " ";
    }
    cout << "\n";
}

void run();

#define TASK ""

int main() {
#ifdef LOCAL
    if (strlen(TASK) > 0) {
        cerr << "Reminder: you are using file i/o, filename: " TASK "!" << endl << endl;
    }
#endif
#ifndef LOCAL
    if (strlen(TASK)) {
        freopen(TASK ".in", "r", stdin);
        freopen(TASK ".out", "w", stdout);
    }
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
#endif
    cout << fixed << setprecision(12);
    run();
    return 0;
}

// == SOLUTION == //

const int N = 2005;

int n;
bool a[N], b[N];
int l[N], r[N];

void run() {
    string aa, bb;
    cin >> aa >> bb;
    n = sz(aa);
    rep(i, 0, n) {
        a[i] = aa[i] == '1';
        b[i] = bb[i] == '1';
    }
    
    rep(i, 0, n) {
        l[i] = INF;
        rep(d, 0, n) {
            int pos = sum(i, -d, n);
            if (b[pos]) {
                l[i] = d;
                break;
            }
        }
        r[i] = INF;
        rep(d, 0, n) {
            int pos = sum(i, d, n);
            if (b[pos]) {
                r[i] = d;
                break;
            }
        }
    }
    
    int ans = INF;
    
    rep(shift, 0, n + 1) {
        multiset<int> q;
        vector<pair<int, int>> bad;
        int diff = 0;
        rep(i, 0, n) {
            int j = sum(i, shift, n);
            if (a[j] == b[i]) continue;
            diff++;
            if (l[j] > shift) {
                q.insert(r[j]);
                bad.pb({l[j], j});
            }
        }
        sort(all(bad));
        reverse(all(bad));
        if (sz(q) && *q.rbegin() == INF) {
            continue;
        }
        rep(add_shift, 0, n - shift + 1) {
            int cur_shift = shift + add_shift;
            while (sz(bad) && bad.back().first <= cur_shift) {
                q.erase(q.find(r[bad.back().second]));
                bad.pop_back();
            }
            int right = (!sz(q) ? 0 : *q.rbegin());
            if (right != INF) {
                mini(ans, shift + add_shift * 2 + right * 2 + diff);
            }
        }
    }
    
    rep(shift, 0, n + 1) {
        multiset<int> q;
        vector<pair<int, int>> bad;
        int diff = 0;
        rep(i, 0, n) {
            int j = sum(i, -shift, n);
            if (a[j] == b[i]) continue;
            diff++;
            if (r[j] > shift) {
                q.insert(l[j]);
                bad.pb({r[j], j});
            }
        }
        sort(all(bad));
        reverse(all(bad));
        if (sz(q) && *q.rbegin() == INF) {
            continue;
        }
        rep(add_shift, 0, n - shift + 1) {
            int cur_shift = shift + add_shift;
            while (sz(bad) && bad.back().first <= cur_shift) {
                q.erase(q.find(l[bad.back().second]));
                bad.pop_back();
            }
            int left = (!sz(q) ? 0 : *q.rbegin());
            if (left != INF) {
                mini(ans, shift + add_shift * 2 + left * 2 + diff);
            }
        }
    }
    
    cout << (ans == INF ? -1 : ans) << "\n";
}


Measured memory_bytes: 384