// Copyright (C) 2017 __debug.

// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as
// published by the Free Software Foundation; version 3

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program; If not, see <http://www.gnu.org/licenses/>.


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/priority_queue.hpp>

#define x first
#define y second
#define MP std::make_pair
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(), (x).end()
#define DEBUG(...) fprintf(stderr, __VA_ARGS__)
#ifdef __linux__
#define getchar getchar_unlocked
#define putchar putchar_unlocked
#endif

using std::pair;
using std::vector;
using std::string;

typedef long long LL;
typedef pair<int, int> Pii;

const int oo = 0x3f3f3f3f;

template<typename T> inline bool chkmax(T &a, T b) { return a < b ? a = b, true : false; }
template<typename T> inline bool chkmin(T &a, T b) { return b < a ? a = b, true : false; }
string procStatus()
{
    std::ifstream t("/proc/self/status");
    return string(std::istreambuf_iterator<char>(t), std::istreambuf_iterator<char>());
}
template<typename T> T read(T &x)
{
    int f = 1;
    char ch = getchar();
    for (; !isdigit(ch); ch = getchar())
        f = (ch == '-' ? -1 : 1);
    for (x = 0; isdigit(ch); ch = getchar())
        x = 10 * x + ch - '0';
    return x *= f;
}
template<typename T> void write(T x)
{
    if (x == 0) {
        putchar('0');
        return;
    }
    if (x < 0) {
        putchar('-');
        x = -x;
    }
    static char s[20];
    int top = 0;
    for (; x; x /= 10)
        s[++top] = x % 10 + '0';
    while (top)
        putchar(s[top--]);
}
// EOT

const int MAXN = 2e3 + 5;

int N;
char A[MAXN], B[MAXN];

void input()
{
    scanf("%s", A);
    scanf("%s", B);
    N = strlen(A);
    for (int i = 0; i < N; ++i) A[i] -= '0';
    for (int i = 0; i < N; ++i) B[i] -= '0';
}

int ans;

void calc()
{
    static int prev[MAXN], next[MAXN];
    int s = N, t = -1;

    for (int i = 0; i < N; ++i) {
        if (B[i]) {
            chkmin(s, i);
            chkmax(t, i);
        }
    }
    prev[0] = B[0] ? 0 : t;
    for (int i = 1; i < N; ++i) prev[i] = B[i] ? i : prev[i - 1];
    next[N - 1] = B[N - 1] ? N - 1 : s;
    for (int i = N - 2; i >= 0; --i) next[i] = B[i] ? i : next[i + 1];

    vector<Pii> list;

    for (int i = 0; i <= N * 2; ++i) {
        list.clear();
        for (int j = 0; j < N; ++j) {
            if (A[j] != B[(j + i) % N]) {
                list.push_back(MP((next[j] - j + N) % N, (j - prev[j] + N) % N));
            }
        }
        if (SZ(list) == 0) {
            chkmin(ans, i);
            continue;
        }
        std::sort(ALL(list));

        static int sufmax[MAXN];

        sufmax[SZ(list)] = 0;
        for (int j = SZ(list) - 1; j >= 0; --j) {
            sufmax[j] = std::max(sufmax[j + 1], list[j].y);
        }
        chkmin(ans, SZ(list) + i + sufmax[0] * 2);
        for (int j = 0; j < SZ(list); ++j) {
            int l = std::max(list[j].x, i), r = sufmax[j + 1];
            chkmin(ans, SZ(list) + (l + r) * 2 - i);
        }
    }
}

void solve()
{
    int sum = 0;
    for (int i = 0; i < N; ++i) sum += B[i];
    if (sum == 0) {
        for (int i = 0; i < N; ++i) sum += A[i];
        puts(sum == 0 ? "0" : "-1");
        return;
    }

    ans = +oo;
    calc();
    std::reverse(A, A + N);
    std::reverse(B, B + N);
    calc();

    printf("%d\n", ans);
}

int main()
{
#ifdef __DEBUG
    freopen("D.in", "r", stdin);
    freopen("D.out", "w", stdout);
#endif

    input();
    solve();

    return 0;
}

// 独自凄凉还自遣，自制离愁。
//     -- 龚自珍《浪淘沙·写梦》


Measured memory_bytes: 256