#include "bits/stdc++.h"

using namespace std;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

using ll = long long;
using ld = long double;

constexpr int nax = 2005;
constexpr int infty = 1000 * 1000 * 1000 + 5;
constexpr int mod = 1000 * 1000 * 1000 + 7;

int n;
int A[nax], B[nax], C[nax];
int lewo[nax], prawo[nax];

int Dawaj(int cel) {
  for (int i = 0; i < n; i++) {
    C[i] = A[i] ^ B[(i - cel + n) % n];
  }
  for (int i = 0; i < n; i++) {
    lewo[i] = prawo[i] = n;
  }
  for (int pow = 0; pow < 2; pow++) {
    for (int i = 0; i < n; i++) {
      if (B[i]) lewo[i] = 0;
      lewo[i] = min(lewo[i], lewo[(i - 1 + n) % n] + 1);
    }
    for (int i = n - 1; i >= 0; i--) {
      if (B[i]) prawo[i] = 0;
      prawo[i] = min(prawo[i], prawo[(i + 1) % n] + 1);
    }
  }
  int dodaj = 0;
  vector<pair<int, int>> pary;
  pary.emplace_back(0, 0);
  for (int i = 0; i < n; i++) {
    if (C[i]) {
      dodaj++;
      debug() << imie(lewo[i]) imie(prawo[i]);
      swap(lewo[i], prawo[i]);
      if (0 < lewo[i] and prawo[i] > cel) {
        pary.emplace_back(lewo[i], prawo[i]);
      }
    }
  }
  debug() << imie(cel) imie(range(C, C + n)) imie(pary) imie(dodaj);
  sort(pary.begin(), pary.end(),
       [](const pair<int, int>& a, const pair<int, int>& b) -> bool {
         return a > b;
       });
  int wynik = 2 * n + dodaj;
  int dalej = cel;
  for (const auto& p : pary) {
    wynik = min(wynik, p.first * 2 + dalej * 2 - cel + dodaj);
    dalej = max(dalej, p.second);
  }
  debug() << imie(wynik);
  return wynik;
}

int Licz() {
  while (B[0] == 0) {
    for (int* t : {A, B}) {
      int x = t[0];
      for (int i = 1; i < n; i++) {
        t[i - 1] = t[i];
      }
      t[n - 1] = x;
    }
  }
  debug() << imie(n);
  debug() << imie(range(A, A + n));
  debug() << imie(range(B, B + n));
  int wynik = 100 * n;
  for (int i = 0; i < n; i++) {
    wynik = min(wynik, Dawaj(i));
  }
  return wynik;
}

char tmp[nax];
int main() {
  scanf("%s", tmp);
  n = strlen(tmp);
  bool jedynka[2] = {false, false};
  for (int i = 0; i < n; i++) {
    A[i] = tmp[i] - '0';
    if (A[i]) jedynka[0] = true;
  }
  scanf("%s", tmp);
  for (int i = 0; i < n; i++) {
    B[i] = tmp[i] - '0';
    if (B[i]) jedynka[1] = true;
  }
  if (!jedynka[1]) {
    if (jedynka[0]) printf("-1\n");
    else printf("0\n");
    return 0;
  }
  const int wynik = Licz();
  for (int i = 0; i < n / 2; i++) {
    swap(A[i], A[n - 1 - i]);
    swap(B[i], B[n - 1 - i]);
  }
  const int wynik2 = Licz();
  debug() << imie(wynik) imie(wynik2);
  printf("%d\n", min(wynik, wynik2));
  return 0;
}


Measured memory_bytes: 256