#pragma comment(linker, "/STACK:512000000")
#define _CRT_SECURE_NO_WARNINGS
//#include "testlib.h"
#include <bits/stdc++.h>
using namespace std;

#define all(a) a.begin(), a.end()
typedef long long li;
typedef long double ld;
void solve(bool);
void precalc();
clock_t start;
int main() {
#ifdef AIM
  freopen("/home/alexandero/ClionProjects/ACM/input.txt", "r", stdin);
  //freopen("/home/alexandero/ClionProjects/ACM/output.txt", "w", stdout);
  //freopen("out.txt", "w", stdout);
#else
  //freopen("input.txt", "r", stdin);
  //freopen("output.txt", "w", stdout);
#endif
  start = clock();
  int t = 1;
  cout.sync_with_stdio(0);
  cin.tie(0);
  precalc();
  cout.precision(10);
  cout << fixed;
  //cin >> t;
  int testNum = 1;
  while (t--) {
    //cout << "Case #" << testNum++ << ": ";
    //cerr << testNum << endl;
    solve(true);
    //cerr << testNum - 1 << endl;
  }
  cout.flush();
#ifdef AIM1
  while (true) {
      solve(false);
  }
#endif

#ifdef AIM
  cerr << "\n\n time: " << (clock() - start) / 1.0 / CLOCKS_PER_SEC << "\n\n";
#endif

  return 0;
}

//BE CAREFUL: IS INT REALLY INT?

template<typename T>
T binpow(T q, T w, T mod) {
  if (!w)
    return 1 % mod;
  if (w & 1)
    return q * 1LL * binpow(q, w - 1, mod) % mod;
  return binpow(q * 1LL * q % mod, w / 2, mod);
}

template<typename T>
T gcd(T q, T w) {
  while (w) {
    q %= w;
    swap(q, w);
  }
  return q;
}
template<typename T>
T lcm(T q, T w) {
  return q / gcd(q, w) * w;
}

template <typename T>
void make_unique(vector<T>& a) {
  sort(all(a));
  a.erase(unique(all(a)), a.end());
}

void precalc() {

}

template<typename T>
void relax_min(T& cur, T val) {
  cur = min(cur, val);
}

template<typename T>
void relax_max(T& cur, T val) {
  cur = max(cur, val);
}

//#define int li
//const int mod = 1000000007;

int n;

void relax(int& ans, int lef, int rig, int shift, int cnt) {
    if (rig <= shift) {
        relax_min(ans, 2 * lef + shift + cnt);
    } else {
        relax_min(ans, 2 * lef + shift + 2 * (rig - shift) + cnt);
    }
    shift = (n - shift) % n;
    swap(lef, rig);
    if (rig <= shift) {
        relax_min(ans, 2 * lef + shift + cnt);
    } else {
        relax_min(ans, 2 * lef + shift + 2 * (rig - shift) + cnt);
    }
}

void solve(bool read) {
    string a, b;
    //read = false;
    if (read) {
        cin >> a >> b;
    } else {
        a = string(2000, '1');
        b= string(2000, '1');
        for (int i = 0 ;i < 2000; ++i) {
            if (rand() & 1) {
                a[i] = '0';
            }
            if (rand() & 1) {
                b[i] = '0';
            }
        }
    }
    n = a.length();
    vector<int> left_one(n, n + 1), right_one(n, n + 1);
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            if (b[j] == '1') {
                relax_min(left_one[i], (i - j + n) % n);
                relax_min(right_one[i], (j - i + n) % n);
            }
        }
    }
    if (left_one[0] == n + 1) {
        if (a == b) {
            cout << "0\n";
        } else {
            cout << "-1\n";
        }
        return;
    }

    int ans = 1e9;
    for (int shift = 0; shift < n; ++shift) {
        vector<int> max_q(n);
        int cnt = 0;
        for (int i = 0; i < n; ++i) {
            if (a[i] != b[(i + shift) % n]) {
                relax_max(max_q[left_one[i]], right_one[i]);
                ++cnt;
            }
        }
        int max_right = 0;
        for (int l = n - 1; l >= 0; --l) {
            relax(ans, l, max_right, shift, cnt);
            relax_max(max_right, max_q[l]);
        }

        //cout << shift << " " << ans << endl;

    }

    cout << ans << endl;

}

Measured memory_bytes: 256