#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
int N;
char S[2005];
int A[2005], B[2005], Right[2005], Left[2005], Max[2005];
int sum, sum2;
int ans = 1000000005;
pair <int, int> X[2005];
void Read()
{

    cin.getline(S + 1, 2005);
    N = strlen(S + 1);
    for(int i = 1; i <= N; i++)
    {
        A[i] = S[i] - '0';
        sum += A[i];
    }
    cin.getline(S + 1, 2005);
    for(int i = 1; i <= N; i++)
        B[i] = S[i] - '0', sum2 += B[i];
}
inline int Val(int pos)
{
    if(pos <= 0)
        pos += N;
    if(pos > N)
        pos -= N;
    return B[pos];
}
void precalcLeftRight()
{
    for(int i = 1; i <= N; i++)
    {
        int j = 0;
        while(j > -N && Val(i + j) == 0)
            --j;
        Left[i] = j;
        j = 0;
        while(j < N && Val(i + j) == 0)
            ++j;
        Right[i] = j;
    }
}

void Solve(int d)
{
    int cnt = 0;
    for(int i = 1; i <= N; i++)
    {
        int pos = i + d;
        if(pos <= 0)
        pos += N;
    if(pos > N)
        pos -= N;
        if(B[pos] != A[i])
            X[++cnt] = make_pair(min(0, d + Left[pos]), max(0, d + Right[pos]));
    }
    sort(X + 1, X + cnt + 1);
    for(int i = 1; i <= cnt; i++)
    {
        Max[i] = max(Max[i - 1], X[i].second);
    }
    X[cnt + 1].first = min(d, 0);
    Max[0] = max(0, d);
    for(int i = cnt + 1; i >= 1; i--)
    {
        int l = X[i].first, r = Max[i - 1];
        ans = min(ans, (r - l) * 2 - max(d, -d) + cnt);
    }
}
int main()
{
    Read();
    if(sum2 == 0)
    {
        if(sum == 0)
            cout << "0\n";
        else
            cout << "-1\n";
        return 0;
    }
    precalcLeftRight();
    for(int d = -N + 1; d <= N - 1; d++)
        Solve(d);
    cout << ans << "\n";
    return 0;
}
