#include <bits/stdc++.h>
using namespace std;

typedef pair <int, int> ii;
const int maxn = 2222;

int N;
int L[maxn], R[maxn];
char A[maxn], B[maxn];

int add(int x, int y) {
    x += y;
    if (x >= N) x -= N;
    if (x < 0) x += N;
    return x;
}

int main() {
//    freopen("input.in", "r", stdin);
  //  freopen("output.out", "w", stdout);

    scanf("%s%s", A, B);
    N = strlen(A);
    int c1 = 0, c2 = 0;
    for (int i = 0; i < N; ++i) {
        c1 += A[i] == '1';
        c2 += B[i] == '1';
    }
    if (!c2) {
        puts(!c1 ? "0" : "-1");
        return 0;
    }
    for (int i = 0; i < N; ++i) {
        for (L[i] = 0; B[add(i, -L[i])] == '0'; L[i]++);
        for (R[i] = 0; B[add(i, R[i])] == '0'; R[i]++);
    }
    int ans = 1e9 + 7;
    for (int d = -N; d <= N; ++d) {
        int cnt = 0;
        vector <ii> c;
        for (int i = 0; i < N; ++i) {
            int id = (i + d + N) % N;
            if (A[i] == B[id]) continue;
            cnt++;
            int lo = L[i] - max(-d, 0);
            int hi = R[i] - max(d, 0);
            if (lo >= 0 && hi >= 0) c.push_back(ii(lo, hi));
        }
        int cur = 1e9 + 7;
        sort(c.begin(), c.end());
        int mx = 0;
        for (int i = (int) c.size() - 1; i >= 0; --i) {
            cur = min(cur, c[i].first + mx);
            mx = max(mx, c[i].second);
        }
        cur = min(cur, mx);
        ans = min(ans, abs(d) + 2 * cur + cnt);
    }
    printf("%d\n", ans);

    return 0;
}
