#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;

template <typename T1, typename T2>
string print_iterable(T1 begin_iter, T2 end_iter, int counter) {
    bool done_something = false;
    stringstream res;
    res << "[";
    for (; begin_iter != end_iter and counter; ++begin_iter) {
        done_something = true;
        counter--;
        res << *begin_iter << ", ";
    }
    string str = res.str();
    if (done_something) {
        str.pop_back();
        str.pop_back();
    }
    str += "]";
    return str;
}

vector<int> SortIndex(int size, std::function<bool(int, int)> compare) {
    vector<int> ord(size);
    for (int i = 0; i < size; i++) ord[i] = i;
    sort(ord.begin(), ord.end(), compare);
    return ord;
}

template <typename T>
bool MinPlace(T& a, const T& b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

template <typename T>
bool MaxPlace(T& a, const T& b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

template <typename Container>
int SZ(const Container& S) { return S.size(); }

template <typename S, typename T>
ostream& operator <<(ostream& out, const pair<S, T>& p) {
    out << "{" << p.first << ", " << p.second << "}";
    return out;
}

template <typename T>
ostream& operator <<(ostream& out, const vector<T>& v) {
    out << "[";
    for (int i = 0; i < (int)v.size(); i++) {
        out << v[i];
        if (i != (int)v.size()-1) out << ", ";
    }
    out << "]";
    return out;
}

#if DEBUG && !ONLINE_JUDGE
    ifstream input_from_file("input.txt");
    #define cin input_from_file

    #define dbg_var(x) clog << #x  << ": " << x << endl;
    #define dbg_array(x, len) clog << #x << ": " << print_iterable(x, x+len, -1) << endl;
#else
    #define dbg_var(x)
    #define dbg_array(x, len)
#endif

///////////////////////////////////////////////////////////////////////////
//////////////////// DO NOT TOUCH BEFORE THIS LINE ////////////////////////
///////////////////////////////////////////////////////////////////////////

const int MAXN = 2500;
int dist_after[MAXN];
int dist_before[MAXN]; 

int N;
string A, B;

int SolveProb() {
    for (int i = 0; i < N; i++) {
        for (int d = 0; d < N; d++) {
            if (B[(i+d)%N] == '1') {
                dist_after[i] = d;
                break;
            }
        }
        for (int d = 0; d < N; d++) {
            if (B[(i+N-d)%N] == '1') {
                dist_before[i] = d;
                break;
            }
        }
    }
    int res = 10*MAXN;
    for (int s = 0; s < N; s++) {
        int wrong = 0;
        vector<pair<int,int>> bef_aft;
        for (int i = 0; i < N; i++) {
            if (A[i] == B[(i+s) % N]) continue;
            wrong++;
            if (dist_after[i] <= s) continue;
            bef_aft.push_back({dist_before[i], dist_after[(i+s)%N]});
        }
        int min_sum = 10*MAXN;
        int curr_max = 0;
        sort(bef_aft.begin(), bef_aft.end());
        reverse(bef_aft.begin(), bef_aft.end());
        for (auto pp : bef_aft) {
            min_sum = min(min_sum, pp.first + curr_max);
            curr_max = max(curr_max, pp.second);
        }
        min_sum = min(min_sum, curr_max);

        res = min(res, s + wrong + 2*min_sum);
    }
    return res;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0); // Remove in problems with online queries!

    cin >> A >> B;
    N = A.size();
    bool a1 = false;
    bool b1 = false;
    for (int i = 0; i < N; i++) {
        a1 |= A[i] == '1';
        b1 |= B[i] == '1';
    }
    if (!b1 and !a1) {
        cout << 0 << "\n";
        return 0;
    }
    if (!b1 and a1) {
        cout << -1 << "\n";
        return 0;
    }
    int res1 = SolveProb();
    reverse(A.begin(), A.end());
    reverse(B.begin(), B.end());
    int res2 = SolveProb();

    cout << min(res1, res2) << "\n";
}



Measured memory_bytes: 256