#include <bits/stdc++.h>
using namespace std;
#define FOR(i, begin, end) for(int i=(begin);i<(int)(end);i++)
#define REP(i, n) FOR(i,0,n)

template <typename T>
class SegTree
{
    int N;
    int head;
    vector<T> x;
    T defaultT;
    using func = function<T(const T&, const T&)>;
    func tree_update;

    T _query_search(int begin, int end, int pos, int l, int r)
    {
        if (r <= begin || l >= end) return defaultT;
        if (l >= begin && r <= end) return x[pos];
        T v_l = _query_search(begin, end, 2*pos+1, l, (l+r)/2);
        T v_r = _query_search(begin, end, 2*pos+2, (l+r)/2, r);
        return tree_update(v_l, v_r);
    }

public:
    SegTree(int N, T val_default, func f) : N(N), defaultT(val_default), tree_update(f)
    {
        int N_tmp = 1;
        while (N_tmp < N) N_tmp <<= 1;
        x = vector<T>(N_tmp*2, defaultT);
        head = N_tmp - 1;
    }

    void update(int pos, T val)
    {
        pos += head;
        x[pos] = val;
        while (pos)
        {
            pos = (pos - 1) / 2;
            x[pos] = tree_update(x[pos*2+1], x[pos*2+2]);
        }
    }
    T query(int begin, int end)
    {
        return _query_search(begin, end, 0, 0, (int)x.size() / 2);
    }
};


string A, _B;
int N;
constexpr int Nmax = 2000;
array<int, Nmax> right_, left_;

inline bool B(const int &i) {
    return _B[(i % N + N) % N] == '1';
}

int main()
{
    cin >> A >> _B;
    N = A.length();
    
    {
        // コーナーケース（B全部0）
        bool abn = true;
        REP(i, N) if (B(i)) abn = false;
        if (abn) // Bが全部0
        {
            int n = 0;
            REP(i, N) n += A[i] - '0';
            cout << (n ? -1 : 0) << endl;
            return 0;
        }
    }

    {
        // build right_
        int last1 = -1;
        int now = 0;
        while (last1 < N - 1) {
            if (B(now)) {
                while (last1 < now) {
                    last1++;
                    if (last1 >= N) break;
                    right_[last1] = now - last1;
                }
            }
            now++;
        }
    }
    {
        // build left_
        int last1 = N;
        int now = N - 1;
        while (last1 > 0) {
            if (B(now)) {
                while (last1 > now) {
                    last1--;
                    if (last1 < 0) break;
                    left_[last1] = last1 - now;
                }
            }
            now--;
        }
    }
    // REP(i, N) cerr << right_[i] << " "; cout << endl;
    // REP(i, N) cerr << left_[i] << " "; cout << endl;

    using pint = pair<int, int>;
    SegTree<int> rMq(N, 0, [](int a, int b) { return max(a, b); });

    int res = 1000000000;
    FOR(d, -N, N + 1)
    {
        int unmatch = abs(d);
        vector<pint> yori; // 左、右
        yori.push_back((pint(0, 0)));
        REP(i, N) // i文字目
        {
            if (A[i] == '0' && B(i + d) == 1) unmatch++;
            if (A[i] == '1' && B(i + d) == 0) {
                unmatch++;
                if (d < 0 && left_[i] <= -d) continue;
                else if (d >= 0 && right_[i] <= d) continue;
                else {
                    if (d < 0) yori.push_back(pint((left_[i] + d) * 2, right_[i] * 2));
                    else yori.push_back(pint(left_[i] * 2, (right_[i] - d) * 2));
                }
            }
        }
        sort(yori.begin(), yori.end());
        // for (auto v : yori) cerr << v.first << " " << v.second << endl;
        REP(i, yori.size()) rMq.update(i, yori[i].second);
        int tmp = 1000000000;
        REP(i, yori.size()) tmp = min(tmp, yori[i].first + rMq.query(i + 1, yori.size()));
        res = min(res, unmatch + tmp);
    }
    cout << res << endl;
}


Measured memory_bytes: 256