#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <queue>
#include <vector>
#include <stack>
#include <cmath>
#include <memory.h>
#include <iomanip>
#include <cassert>
using namespace std;

#define maxn 2002
#define FOR(i, l, r) for (int i=l; i<=r; ++i)
#define FORD(i, r, l) for (int i=r; i>=l; --i)
#define REP(i, r) for (int i=0; i<(int)r; ++i)
#define REPD(i, r) for (int i=(int)r-1; i>=0; --i)
#define fi first
#define se second
#define mk make_pair
#define nil NULL
#define y0 y902
#define y1 y232
#define x0 x92
#define x1 x899
#define next asdfa
#define sz size
#define Debug(X) {cerr << #X << " = " << X << '\n';}
#define PR(A, n) {cerr << #A << " = "; FOR(i, 1, n) cerr << A[i] << ' '; cerr << '\n';}
#define PR0(A, n) {cerr << #A << " = "; REP(i, n) cerr << A[i] << ' '; cerr << '\n';}
typedef long long ll;
typedef double db;
typedef pair<db, db> dd;
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef vector<int> vi;
const int inf = 1e9;
template<class T> int getbit(T x, int pos) {return (x>>(pos-1)) & 1;}
template<class T> void turn_on(T &x, int pos) {x = x | ((T)1<<(pos-1));}
template<class T> void turn_off(T &x, int pos) {x = x & ~((T)1<<(pos-1));}
template<class T> T sqr(T a) {return a*a;}

string s1, s2;
int Left[maxn], Right[maxn], leftmost = inf;
int rightmost = -inf, MAX[maxn];
vector<iii> p;

int main() {
    //freopen("shift.inp", "r", stdin);
    //freopen("shift.out", "w", stdout);
    ios::sync_with_stdio(0); cin.tie(0);
    cin >> s1 >> s2;
    bool ok1 = false, ok2 = true;
    REP(i, s2.sz()) {
        ok1 = ok1 || (s2[i]=='1');
    }
    REP(i, s1.sz()) {
        ok2 = ok2 && (s1[i]!='1');
        if (s2[i]=='1') {
            leftmost = min(leftmost, i);
            rightmost = max(rightmost, i);
        }
    }
    if (!ok1) {
        cout << (ok2 ? 0 : -1);
        return 0;
    }
    REP(i, s1.sz()) {
        if (s2[i]=='1') Left[i] = 0;
        else {
            if (i==0) Left[i] = s1.sz() - rightmost;
            else Left[i] = Left[i-1] + 1;
        }
    }
    REPD(i, s2.sz()) {
        if (s2[i]=='1') Right[i] = 0;
        else {
            if (i==(int)s2.sz()-1) Right[i] = leftmost+1;
            else Right[i] = Right[i+1] + 1;
        }
    }
    REP(i, s1.sz()) p.push_back(iii(ii(Left[i], Right[i]), i));
    sort(p.begin(), p.end());
    int res = inf, n = s1.sz();
    REP(t, s1.sz()) {
        int tmp = inf;
        REPD(i, p.sz()) {
            MAX[i] = MAX[i+1];
            if (s1[p[i].se]!=s2[(p[i].se+t)%n])
                MAX[i] = max(MAX[i], p[i].fi.se);
        }
        REP(i, p.sz()) {
            //if (s1[i]==s2[(i+t)%n]) continue;
            if (MAX[i+1]==0) tmp = min(tmp, p[i].fi.fi+min(abs(n-p[i].fi.fi-t), n-abs(n-p[i].fi.fi-t)));
            if (p[i].fi.fi==0) tmp = min(tmp, MAX[i+1]+min(abs(MAX[i+1]-t), n-abs(MAX[i+1]-t)));
            tmp = min(tmp, 2*p[i].fi.fi+MAX[i+1]+min(abs(MAX[i+1]-t), n-abs(MAX[i+1]-t)));
            tmp = min(tmp, 2*MAX[i+1]+p[i].fi.fi+min(abs(n-p[i].fi.fi-t), n-abs(n-p[i].fi.fi-t)));
        }
        REP(i, s1.sz()) {
            tmp += (s1[i]!=s2[(i+t)%s1.sz()]);
        }
        res = min(res, tmp);
    }
    cout << res;
}



Measured memory_bytes: 384