#define STOPIT
#include <bits/stdc++.h>
#define loop(n) for (int ngtkana_is_genius = 0; ngtkana_is_genius < int(n); ngtkana_is_genius++)
#define rep(i, begin, end) for(int i = int(begin); i < int(end); i++)
#define all(v) v.begin(), v.end()
#define rand(l, r) std::uniform_int_distribution<>(l, r)(mt)
#define lint long long
auto cmn = [](auto& a, auto b){if (a > b) {a = b; return true;} return false;};
auto cmx = [](auto& a, auto b){if (a < b) {a = b; return true;} return false;};
void debug_impl() { std::cerr << std::endl; }
template <typename Head, typename... Tail>
void debug_impl(Head head, Tail... tail){
  std::cerr << " " << head;
  debug_impl(tail...);
}
#ifndef STOPIT
#define debug(...)\
  std::cerr << std::boolalpha << "[" << #__VA_ARGS__ << "]:";\
  debug_impl(__VA_ARGS__);\
  std::cerr << std::noboolalpha;
#else
#define debug 0;
#endif

template < typename Container,
  typename Value = typename Container::value_type,
  std::enable_if_t<!std::is_same< Container, std::string >::value, std::nullptr_t> = nullptr
>
std::istream& operator>> (std::istream& is, Container& v) {
  for (auto & x : v) is >> x;
  return is;
}

template < typename Container,
  typename Value = typename Container::value_type,
  std::enable_if_t<!std::is_same< Container, std::string >::value, std::nullptr_t> = nullptr
>
std::ostream& operator<< (std::ostream& os, Container const& v) {
  os << "{";
  for (auto it = v.begin(); it != v.end(); it++)
    {os << (it != v.begin() ? "," : "") << *it;}
  return os << "}";
}

template <typename T, typename U>
std::ostream& operator<< (std::ostream& os, const std::pair<T, U>& pair)
  { return os << "(" << pair.first << "," << pair.second << ")"; }

template <typename T, typename U>
std::istream& operator>> (std::iostream& is, std::pair<T, U>& pair)
  { return is >> pair.first >> pair.second; }

template < typename Container, typename = typename Container::value_type >
inline auto extend(Container const& v, int k) {
  auto ret = Container(k);
  for (auto i = 0; i < k; i++)
    { ret.at(i) = v.at(i % (int)v.size()); }
  return ret;
}

int main() {
  std::cin.tie(0); std::cin.sync_with_stdio(false);
  constexpr int inf = 1 << 30;
  std::string s, t; std::cin >> s >> t;
  int n = s.length();
  std::vector< int > a(n), b(n);
  std::transform(all(s), a.begin(), [](auto c){ return c == '1'; });
  std::transform(all(t), b.begin(), [](auto c){ return c == '1'; });
  if (std::none_of(all(b), [](auto x){ return x; })) {
    auto possible = std::none_of(all(a), [](auto x){ return x; });
    auto ret = possible ? 0 : -1;
    std::cout << ret << std::endl;
    return 0;
  }
  auto N = 3 * n;
  a = extend(a, N);
  b = extend(b, N);

  auto minimize = [&] (auto&& seq) {
    std::vector< int > y(n, 0);
    for (auto p : seq)
      { cmx(y.at(p.first), p.second); }
    auto ret = inf;
    auto max = 0;
    for (auto x = n - 1; x >= 0; x--) {
      auto crr = y.at(x);
      cmn(ret, x + max);
      cmx(max, crr);
    }
    return ret;
  };

  auto cal = [&] (auto&& a, auto&& b) {
    debug(a);
    debug(b);
    std::vector< int > prev(N, -1), next(N, N);
    rep(i, 0, N - 1) {
      auto j = N - 1 - i;
      prev.at (i + 1) = b.at(i) ? i : prev.at(i);
      next.at(j - 1) = b.at(j) ? j : next.at(j);
    }
    debug(prev);
    debug(next);
    auto noone = [&] (auto x, auto y) {
      if (x == y) { return b.at(x) == 0; }
      return prev.at(x) == prev.at(y) && next.at(x) == next.at(y);
    };

    // test
    loop(0) {
      std::mt19937 mt(std::random_device{}());
      auto l = rand(0, N - 1);
      auto r = rand(0, N - 1);
      if (r < l) std::swap(l, r);
      r++;
      auto z = noone(l, r - 1);
      auto w = std::accumulate(b.begin() + l, b.begin() + r, 0);
      // debug(l, r, z, w);
      assert(z == (w == 0));
    }

    auto ret = inf;
    rep(d, 0, n) {
      auto now = d;
      std::vector< std::pair< int, int > > seq;
      rep(i, n, 2 * n) {
        auto j = i + d;
        auto x = a.at(i), y = b.at(j);
        if (x != y) { now++; }
        if (x == 1 && noone(i, j))
          { seq.emplace_back(i - prev.at(i), next.at(j) - j); }
      }
      now += minimize(seq) * 2;
      debug(d, now, seq);
      cmn(ret, now);
    }
    return ret;
  };
  auto ret = inf;
  cmn(ret, cal(a, b));
  std::reverse(all(a));
  std::reverse(all(b));
  cmn(ret, cal(a, b));
  std::cout << ret << std::endl;
  return 0;
}


Measured memory_bytes: 384