#include <iostream>
#include <map>
#include <set>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <fstream>
#include <bitset>
#include <queue>
#include <stack>
#include <deque>
#include <complex>
#include <iomanip>
#include <stdio.h>
#include <string.h>
#include <random>
#include <functional>

using std::cin;
using std::cout;
using std::cerr;
using std::endl;

using std::map;
using std::set;
using std::bitset;
using std::vector;
using std::string;
using std::multimap;
using std::multiset;
using std::deque;
using std::queue;
using std::stack;
using std::pair;
using std::iterator;

using std::sort;
using std::stable_sort;
using std::reverse;
using std::max_element;
using std::min_element;
using std::unique;
using std::ios_base;
using std::swap;
using std::fill;

using std::setprecision;
using std::fixed;

long long min(long long a, long long b) {return a < b ? a : b;}
long long min(int a, long long b) {return a < b ? a : b;}
long long min(long long a, int b) {return a < b ? a : b;}
long long min(int a, int b) {return a < b ? a : b;}

long long max(long long a, long long b) {return a > b ? a : b;}
long long max(int a, long long b) {return a > b ? a : b;}
long long max(long long a, int b) {return a > b ? a : b;}
long long max(int a, int b) {return a > b ? a : b;}

#define int long long

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef string S;

#define F(i, n) for (int (i) = 0; (i) != (n); (i)++)
#define fi first
#define se second
#define re return
#define all(x) (x).begin(), (x).end()

const int N = 522220;
const int MOD = 1e9 + 7;
const double eps = 1e-8;

int n, ans = 1e9;
string a, b;

bool comp(pair<pii, int> a, pair<pii, int> b)
{
    return a.first.second < b.first.second;
}

void solve()
{
    for (int i = 0; i < n; i++)
    {
        int ops = i;
        vector<int> c(n, 0);
        int cnt = 0;
        for (int j = n - 1; j >= 0; j--)
        {
            if (b[j] == '1') cnt = i + 1;
            if (cnt) cnt--, c[j] = 1;
        }
        for (int j = n - 1; j >= 0; j--)
        {
            if (cnt) cnt--, c[j] = 1;
        }
        for (int j = 0; j < n; j++)
        {
            if (a[j] != b[(j + i) % n]) ops++;
        }
        vector<int> distL(n, 1e9);
        vector<int> distR(n, 1e9);
        for (int j = 1; j < 2 * n; j++)
        {
            if (c[j % n] == 1) distL[j % n] = 0;
            else distL[j % n] = min(distL[j % n], distL[(j - 1) % n] + 1);
        }
        for (int j = 2 * n - 2; j >= 0; j--)
        {
            if (c[j % n] == 1) distR[j % n] = 0;
            else distR[j % n] = min(distR[j % n], distR[(j + 1) % n] + 1);
        }
        vector<pair<pii, int> > s;
        set<pair<pii, int> > ss;
        for (int j = 0; j < n; j++)
        {
            if (a[j] != b[(j + i) % n] && c[j] == 0)
            {
                int L = distL[j], R = distR[j];
                s.push_back({{L, R}, j});
                ss.insert({{L, R}, j});
            }
        }
        sort(all(s), comp);
        int opt = 1e9;
        int used = 0;
        for (int j = 0; j <= s.size(); j++)
        {
            if (ss.size())
            {
                auto it = ss.end();
                it--;
                pair<pii, int> gg = *it;
                opt = min(opt, used + gg.first.first);
            }
            else
            {
                opt = min(opt, used);
            }
            if (j < s.size()) used = s[j].first.second, ss.erase(s[j]);
        }
        //cout << i << " : " << 2 * opt << " " << ops << endl;
        ans = min(ans, min(2 * opt, n) + ops);
    }
}

signed main()
{
    srand(time(NULL));
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> a >> b;
    if (a == b) cout << 0, exit(0);
    n = a.size();
    int c = 0;
    for (int i = 0; i < b.size(); i++) c += b[i] - '0';
    if (c == 0) cout << -1, exit(0);
    solve();
    reverse(all(a));
    reverse(all(b));
    solve();
    cout << ans;
}


Measured memory_bytes: 512