/*
   ЗАПУСКАЕМ СТЕНУ ИЗ КРЕМА
   💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩
   💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩
   💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩
   💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩
   💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩
   💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩
   💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩
   💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩
   💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩
   💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩
   💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩
   💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩
   💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩
   💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩
   💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩
   💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩
   💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩
   💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩
   💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩
   💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩
   💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩
   💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩
   💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩
*/

#include <cmath>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <list>
#include <time.h>
#include <math.h>
#include <random>
#include <deque>
#include <queue>
#include <cassert>
#include <unordered_map>
#include <iomanip>

using namespace std;

typedef long long ll;

mt19937 rnd(228);

const int inf = 1e9 + 7;
int ans = 1e9 + 7;

const int N = 2000 + 1;

int first[N][2];
bool cur[N][2];
bool vis[N][2];

void solve(string s, string t)
{
    int n = (int) s.size();
    for (int it = 0; it < n; it++)
    {
        for (int i = 0; i < n; i++)
        {
            if (it == 0)
            {
                first[i][0] = -1;
                first[i][1] = -1;
                if (s[i] == '1')
                {
                    first[i][1] = 0;
                }
                else
                {
                    first[i][0] = 0;
                }
            }
            int ind = (i + it) % n;
            if (s[i] == '0' && t[ind] == '1')
            {
                if (first[i][1] == -1)
                {
                    first[i][1] = it;
                }
            }
            if (s[i] == '1' && t[ind] == '1')
            {
                if (first[i][0] == -1)
                {
                    first[i][0] = it;
                }
            }
        }
    }
}

void res(string s, string t)
{
    solve(s, t);
    int n = (int) s.size();
    vector <vector <pair <int, int> > > e(n);
    for (int i = 0; i < n; i++)
    {
        cur[i][0] = cur[i][1] = true;
        vis[i][0] = false;
        vis[i][1] = false;
        if (s[i] == '0')
        {
            cur[i][1] = false;
        }
        else
        {
            cur[i][0] = false;
        }
    }
    for (int it = 0; it < n; it++)
    {
        for (int i = 0; i < n; i++)
        {
            int ind = (i - it + n) % n;
            if (t[ind] == '1')
            {
                if (s[i] == '0')
                {
                    if (!cur[i][1])
                    {
                        e[it].push_back({i, 1});
                        cur[i][1] = true;
                    }
                }
                else
                {
                    if (!cur[i][0])
                    {
                        e[it].push_back({i, 0});
                        cur[i][0] = true;
                    }
                }
            }
        }
    }
    for (int it = 0; it < n; it++)
    {
        vector <int> cnt(n + 1);
        int x = 0;
        int need = 0;
        for (int i = 0; i < n; i++)
        {
            int ind = (i - it + n) % n;
            if (s[i] != t[ind])
            {
                if (!vis[i][t[ind] - '0'])
                {
                    cnt[first[i][t[ind] - '0']]++;
                    x = max(x, first[i][t[ind] - '0']);
                }
                need++;
            }
        }
        for (int go = it; go < n; go++)
        {
            for (auto c : e[go])
            {
                int i = c.first, j = c.second;
                int ind = (i - it + n) % n;
                if (s[i] != t[ind])
                {
                    cnt[first[i][j]]--;
                }
            }
            while (x > 0 && cnt[x] == 0)
            {
                x--;
            }
            ans = min(ans, 2 * x + 2 * (go - it) + it + need);
        }
        for (int i = 0; i < n; i++)
        {
            int ind = (i - it + n) % n;
            if (t[ind] == '1')
            {
                if (s[i] == '0')
                {
                    if (!vis[i][1])
                    {
                        vis[i][1] = true;
                    }
                }
                else
                {
                    if (!vis[i][0])
                    {
                        vis[i][0] = true;
                    }
                }
            }
        }
    }
}

int main()
{
#ifdef ONPC
    freopen("a.in", "r", stdin);
#endif
    string s;
    cin >> s;
    string t;
    cin >> t;
    int kek = 0;
    int kok = 0;
    for (auto c : s)
    {
        if (c == '1')
        {
            kok = 1;
        }
    }
    for (auto c : t)
    {
        if (c == '1')
        {
            kek = 1;
        }
    }
    if (!kek)
    {
        cout << (kok ? -1 : 0) << '\n';
        return 0;
    }
    res(s, t);
    reverse(s.begin(), s.end());
    reverse(t.begin(), t.end());
    res(s, t);
    if (ans == inf)
    {
        ans = -1;
    }
    cout << ans << '\n';
}


Measured memory_bytes: 384