#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int INF = 0x3f3f3f3f;
const int maxn = 2030;

int n;
char a[maxn], b[maxn];
int cnt[maxn], nxt[maxn], lst[maxn];
int x[maxn], y[maxn];
vector<int> v[maxn];

int calc()
{
    int ret = 0, mx = 0;
    for(int i = 1; i <= n; i++)
        if(x[i])
        {
            v[x[i]].push_back(i);
            if(x[i] > ret) ret = x[i];
        }
    for(int i = n; i >= 1; i--)
    {
        for(int &j: v[i]) if(y[j] > mx) mx = y[j];
        v[i].clear();
        if(i + mx - 1 < ret) ret = i + mx - 1;
    }
    return ret;
}

int main()
{
    scanf("%s", a + 1);
    scanf("%s", b + 1);
    n = (int)strlen(a + 1);
    for(int i = 1; i <= n; i++)
    cnt[i] = cnt[i - 1] + (b[i] == '1');
    if(cnt[n] == 0)
    {
        for(int i = 1; i <= n; i++)
            if(a[i] == '1')
            {
                puts("-1");
                return 0;
            }
        puts("0");
        return 0;
    }
    for(int i = 1; i <= n; i++)
    {
        int j = i;
        while(b[j] == '0')
        {
            ++j;
            if(j > n) j = 1;
        }
        nxt[i] = j;
    }
    for(int i = 1; i <= n; i++)
    {
        int j = i;
        while(b[j] == '0')
        {
            --j;
            if(j == 0) j = n;
        }
        lst[i] = j;
    }
    int ans = INF;
    for(int k = 1; k <= n; k++)
    {
        memset(x, 0, sizeof(x[0]) * (n + 1));
        memset(y, 0, sizeof(y[0]) * (n + 1));
        int dlt = k - 1;
        for(int i = 1; i <= n; i++)
        {
            int j = i + k - 1;
            while(j > n) j -= n;
            if(a[i] != b[j])
            {
                int lb = i, rb = j;
                if(lb <= rb)
                {
                    if(cnt[lb - 1] == cnt[rb])
                    {
                        if(nxt[j] < j) x[i] = nxt[j] + n - j;
                        else x[i] = nxt[j] - j;
                    }
                }
                else
                {
                    if(!cnt[rb] && cnt[n] == cnt[lb - 1])
                    {
                        if(nxt[j] < j) x[i] = nxt[j] + n - j;
                        else x[i] = nxt[j] - j;
                    }
                }
            }
        }
        for(int i = 1; i <= n; i++)
        {
            int j = i + k - 1;
            while(j > n) j -= n;
            if(a[i] != b[j])
            {
                ++dlt;
                int lb = i, rb = j;
                if(lb <= rb)
                {
                    if(cnt[lb - 1] == cnt[rb])
                    {
                        if(lst[i] <= i) y[i] = i - lst[i];
                        else y[i] = i + n - lst[i];
                    }
                }
                else
                {
                    if(!cnt[rb] && cnt[n] == cnt[lb - 1])
                    {
                        if(lst[i] <= i) y[i] = i - lst[i];
                        else y[i] =  i + n - lst[i];
                    }
                }
            }
        }
        int tmp = dlt + calc() * 2;
        if(tmp < ans) ans = tmp;
    }
    for(int i = 1; i <= n; i++)
    {
        int j = n + 1 - i;
        if(j <= i) break;
        swap(a[i], a[j]);
        swap(b[i], b[j]);
    }
    memset(cnt, 0, sizeof cnt);
    memset(nxt, 0, sizeof nxt);
    memset(lst, 0, sizeof lst);
    for(int i = 1; i <= n; i++)
        cnt[i] = cnt[i - 1] + (b[i] == '1');
    for(int i = 1; i <= n; i++)
    {
        int j = i;
        while(b[j] == '0')
        {
            ++j;
            if(j > n) j = 1;
        }
        nxt[i] = j;
    }
    for(int i = 1; i <= n; i++)
    {
        int j = i;
        while(b[j] == '0')
        {
            --j;
            if(j == 0) j = n;
        }
        lst[i] = j;
    }
    for(int k = 1; k <= n; k++)
    {
        memset(x, 0, sizeof(x[0]) * (n + 1));
        memset(y, 0, sizeof(y[0]) * (n + 1));
        int dlt = k - 1;
        for(int i = 1; i <= n; i++)
        {
            int j = i + k - 1;
            while(j > n) j -= n;
            if(a[i] != b[j])
            {
                int lb = i, rb = j;
                if(lb <= rb)
                {
                    if(cnt[lb - 1] == cnt[rb])
                    {
                        if(nxt[j] < j) x[i] = nxt[j] + n - j;
                        else x[i] = nxt[j] - j;
                    }
                }
                else
                {
                    if(!cnt[rb] && cnt[n] == cnt[lb - 1])
                    {
                        if(nxt[j] < j) x[i] = nxt[j] + n - j;
                        else x[i] = nxt[j] - j;
                    }
                }
            }
        }
        for(int i = 1; i <= n; i++)
        {
            int j = i + k - 1;
            while(j > n) j -= n;
            if(a[i] != b[j])
            {
                ++dlt;
                int lb = i, rb = j;
                if(lb <= rb)
                {
                    if(cnt[lb - 1] == cnt[rb])
                    {
                        if(lst[i] <= i) y[i] = i - lst[i];
                        else y[i] = i + n - lst[i];
                    }
                }
                else
                {
                    if(!cnt[rb] && cnt[n] == cnt[lb - 1])
                    {
                        if(lst[i] <= i) y[i] = i - lst[i];
                        else y[i] = i + n - lst[i];
                    }
                }
            }
        }
        int tmp = dlt + calc() * 2;
        if(tmp < ans) ans = tmp;
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 384