#include <bits/stdc++.h>

using namespace std;

const int N = 1234567;

#define next NEXT
#define prev PREV

int next[N], prev[N];
int at_least[N];

int main() {
  string a, b;
  cin >> a >> b;
  if (a == b) {
    cout << 0 << endl;
    return 0;
  }
  if (b.find("1") == string::npos) {
    cout << -1 << endl;
    return 0;
  }
  int n = a.length();
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (b[(i + j) % n] == '1') {
        next[i] = j;
        break;
      }
    }
    for (int j = 0; j < n; j++) {
      if (b[(i + n - j) % n] == '1') {
        prev[i] = -j;
        break;
      }
    }
  }
  int ans = (int) 1e9;
  for (int shift = -n; shift <= n; shift++) {
    for (int x = 0; x <= n; x++) {
      at_least[x] = 0;
    }
    int flips = 0;
    for (int i = 0; i < n; i++) {
      int j = (i + shift + n) % n;
      if (a[i] != b[j]) {
        flips++;
        int x = min(0, shift) - prev[i];
        int y = next[i] - max(0, shift);
        if (x > 0 && y > 0) {
          at_least[x - 1] = max(at_least[x - 1], y);
        }
      }
    }
    int y = 0;
    for (int x = n; x >= 0; x--) {
      y = max(y, at_least[x]);
      ans = min(ans, 2 * (x + y) + abs(shift) + flips);
    }
  }
  printf("%d\n", ans);
  return 0;
}
