#pragma GCC optimize("O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")

#include <iostream>
#include <string>
#include <vector>
#include <cassert>
#include <algorithm>
#include <map>
#include <queue>

#define pb push_back
#define fi first
#define se second
#define all(v) v.begin(), v.end()

using namespace std;
using ll = int64_t;

struct MinShift {
  int left, right;
};

string A, B;
int N;
vector<int> sums;
vector<MinShift> min_shifts;
vector<int> lefts, rights;
vector<int> maxRight;

inline int doShift(int i, int shift) {
  i += shift;
  while (i < 0) i += N;
  while (i >= N) i -= N;
  return i;
}

inline int sign(int i) {
  if (i > 0) return 1;
  if (i < 0) return -1;
  return 0;
}

bool covered(int left, int right) {
  assert(left <= right);
  return (sums[right] - (left == 0 ? 0 : sums[left - 1])) > 0;
}

bool covered(int initialPos, int finalPos, int direction) {
  if (direction == 1) {
    if (finalPos <= initialPos) {
      return covered(initialPos, N - 1) || covered(0, finalPos);
    } else {
      return covered(initialPos, finalPos);
    }
  }

  if (direction == -1) {
    if (finalPos >= initialPos) {
      return covered(0, initialPos) || covered(finalPos, N - 1);
    } else {
      return covered(finalPos, initialPos);
    }
  }

  assert(direction == 0);
  assert(initialPos == finalPos);

  return false;
}

int getFirstLeft(int pos) {
  return lefts[pos];
}

int getFirstRight(int pos) {
  return rights[pos];
}

MinShift getMinShift(int initialPos, int finalPos, int direction) {
  if (direction == 1) {
    return MinShift{getFirstLeft(initialPos), getFirstRight(finalPos)};
  }

  if (direction == -1) {
    return MinShift{getFirstLeft(finalPos), getFirstRight(initialPos)};
  }

  assert(direction == 0);
  assert(initialPos == finalPos);

  return MinShift{getFirstLeft(initialPos), getFirstRight(initialPos)};
}

int getAddition() {
      sort(all(min_shifts), [](MinShift lhs, MinShift rhs) {
        return lhs.left < rhs.left;
      });
      int M = min_shifts.size();
      maxRight.assign(M, 0);
      for (int i = M - 1; i >= 0; i--) {
        maxRight[i] = min_shifts[i].right;
        if (i + 1 < M)
          maxRight[i] = max(maxRight[i], maxRight[i + 1]);
      }
      int addition = 0;
      if (!min_shifts.empty()) {
        addition = 2 * N;
        for (int i = 0; i < M; i++) {
          int leftAddition = min_shifts[i].left;
          int rightAddition = 0;
          if (i + 1 < M)
            rightAddition = maxRight[i + 1]; 
          int currentAddition = 2 * leftAddition + 2 * rightAddition;
          addition = min(addition, currentAddition);
        }
      }
      return addition;
}

int solveSmart() {
  sums.assign(N, 0);
  for (int i = 0; i < N; i++) {
    if (i > 0) sums[i] = sums[i - 1];
    sums[i] += (B[i] - '0');
  }

  lefts.assign(N, -1);
  rights.assign(N, -1);

  for (int i = 0; i < N; i++) {
    for (int shift = 0; shift <= N; shift++) {
      int j = doShift(i, -shift);
      if (B[j] == '1' && lefts[i] == -1) {
        lefts[i] = shift;
      }
      j = doShift(i, shift);
      if (B[j] == '1' && rights[i] == -1) {
        rights[i] = shift;
      }
    }
  }

  int result = -1;

  for (int shift = -N; shift <= N; shift++) {
    //cerr << "check: " << shift << endl;
    bool fail = false;
    min_shifts.clear();
    int direction = sign(shift);
    int baseResult = abs(shift);
    for (int finalPos = 0; finalPos < N; finalPos++) {
      int initialPos = doShift(finalPos, -shift);
      char targetChar = B[finalPos];
      char finalChar = A[initialPos];
      //cerr << "chars: " << initialPos << " " << finalPos << " " << targetChar << " " << finalChar << endl;
      if (targetChar != finalChar) {
        ++baseResult;
        if (covered(initialPos, finalPos, direction)) {
          //cerr << "covered: " << initialPos << " " << finalPos << endl;
        } else {
          min_shifts.push_back(getMinShift(initialPos, finalPos, direction));
          //cerr << "shift: " << initialPos << " " << finalPos << " " << min_shifts.back().left << " " << min_shifts.back().right << endl;
        }
      }
    }
    for (auto shift : min_shifts) {
      if (shift.left == -1 && shift.right == -1) {
        fail = true;
      }
    }
    if (!fail) {
      //cerr << "not fail" << endl;
      int addition = getAddition();
      for (auto& s : min_shifts)
        swap(s.left, s.right);
      addition = min(addition, getAddition());
      //cerr << "addition: " << addition << endl;

      if (result == -1)
        result = baseResult + addition;
      else
        result = min(result, baseResult + addition);
      //cerr << "result: " << baseResult + addition << endl;
    }
  }

  return result;
}

int solveDumb() {
  map<string, int> cache;
  queue<string> queue;
  cache[A] = 0;
  queue.push(A);
  while (!queue.empty() && !cache.count(B)) {
    string S = queue.front();
    queue.pop();
    for (int i = 0; i < N; i++) {
      if (B[i] == '1') {
        string SS = S;
        SS[i] ^= 1;
        if (!cache.count(SS) || cache[SS] > cache[S] + 1) {
          cache[SS] = cache[S] + 1;
          queue.push(SS);
        }
      }
    }
    {
      string SS = S.back() + S.substr(0, N - 1);
      if (!cache.count(SS) || cache[SS] > cache[S] + 1) {
        cache[SS] = cache[S] + 1;
        queue.push(SS);
      }
    }
    {
      string SS = S.substr(1, N - 1) + S.front();
      if (!cache.count(SS) || cache[SS] > cache[S] + 1) {
        cache[SS] = cache[S] + 1;
        queue.push(SS);
      }
    }
  }
  if (cache.count(B))
    return cache[B];
  return -1;
}

int main() {
  srand(42);
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  cin >> A >> B;
  N = A.size();

  cout << solveSmart() << endl;

  /*while (true) {
    N = 1 + (rand() % 10);
    A.clear();
    B.clear();
    for (int i = 0; i < N; i++) {
      A += char('0' + (rand() & 1));
      B += char('0' + (rand() & 1));
    }
    if (solveSmart() != solveDumb()) {
      cout << A << endl;
      cout << B << endl;
      cout << solveDumb() << endl;
      cout << solveSmart() << endl;
      break;
    }
  }

//  cout << result << endl;*/

  return 0;
}


Measured memory_bytes: 384