#include <bits/stdc++.h>

using namespace std;
typedef  long long ll;
typedef unsigned long long ull;
int inf_int=1e8;
ll inf_ll=4e18;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define pb push_back
const double pi=3.1415926535898;
#define dout if(debug) cout
#define fi first
#define se second
#define sp setprecision
#define siz(a) a.size()
#define sz size()



#define FILE "kebab"

const int MAXN = 1e5+100;

template<typename T>
void print(vector<T>& a){
    for(int i=0;i<a.size();++i){
        if(i>0)
            cout <<" ";
        cout <<a[i];
    }
    cout <<"\n";
}

vector<int> rig[2100];
vector<int> lef[2100];

int mn_left[2100];
int mn_right[2100];
string a,b;
void build(){
    int n = a.size();
    for(int i=0;i<n;++i){
        mn_left[i] = inf_int;
        mn_right[i] = inf_int;
    }
    for(int i=0;i<n;++i){
        if(b[i]=='1'){
            mn_left[i]=mn_right[i]=0;
        }
    }
    for(int e=1;e<=n;++e){
        for(int i=1;i<n;++i)
            rig[e].pb(rig[e-1][i]);
        rig[e].pb(rig[e-1][0]);

        for(int i=0;i<n;++i){
            int v = rig[e][i];
            if(b[i]=='1'){
                mn_right[v] = min(mn_right[v],e);
            }
        }
    }

    for(int e=1;e<=n;++e){
        lef[e].pb(lef[e-1][n-1]);
        for(int i=0;i<n-1;++i)
            lef[e].pb(lef[e-1][i]);


        for(int i=0;i<n;++i){
            int v = lef[e][i];
            if(b[i]=='1'){
                mn_left[v] = min(mn_left[v],e);
            }
        }
    }

}

int ans = inf_int;

int n;
void calc_rig(int x){
    int cur = x;

    vector<pii> c;
    for(int i=0;i<n;++i){
        int v = rig[x][i];
        if(a[v]!=b[i]){
            c.pb({mn_left[v],mn_right[v]});
            cur++;
        }
    }
    c.pb({0,0});
    sort(c.begin(),c.end());
    int m = c.size();
    int mx = 0;
    int res = inf_int;
    for(int i=m-1;i>=0;--i){
        int val1 = c[i].fi,val2 = mx;
        if(mx>x){
            val2 =2*abs(x-mx);
        } else {
            val2 = 0;
        }
        if(2*val1 + val2 < res){
            res = 2*val1 + val2;
        }

        mx = max(mx, c[i].se);
    }
    ans = min(ans, cur  + res);

}

void calc_lef(int x){
    int cur = x;

    vector<pii> c;
    for(int i=0;i<n;++i){
        int v = lef[x][i];
        if(a[v]!=b[i]){
            c.pb({mn_right[v],mn_left[v]});
            cur++;
        }
    }
    c.pb({0,0});
    sort(c.begin(),c.end());
    int m = c.size();
    int mx = 0;
    int res = inf_int;
    for(int i=m-1;i>=0;--i){
        int val1 = c[i].fi,val2 = mx;
        if(mx>x){
            val2 =2*abs(x-mx);
        } else {
            val2 = 0;
        }
        if(2*val1 + val2 < res){
            res = 2*val1 + val2;
        }

        mx = max(mx, c[i].se);
    }
    ans = min(ans, cur  + res);
}
void solve(){
    cin >> a >> b;
    int cnt = 0;
    for(char c:b){
        if(c=='1')
            cnt++;
    }
    if(a==b){
        cout <<0<<"\n";
        return;
    }
    if(cnt==0){
        cout << "-1\n";
        return;
    }

    n = a.size();
    for(int i=0;i<n;++i){
        rig[0].pb(i);
        lef[0].pb(i);
    }
    build();
    /*for(int i=0;i<n;++i){
        cout << mn_left[i]<<" "<<mn_right[i]<<"\n";
    }*/
    for(int i=0;i<n;++i){
        calc_rig(i);
    }
    for(int i=0;i<n;++i){
        calc_lef(i);
    }
    cout << ans<<"\n";




}
int main()
{
    #ifdef zxc
        freopen("input.txt","r",stdin);
      //  freopen("output1.txt","w",stdout);
    #else
       // freopen(FILE".in","r",stdin);
     //  freopen(FILE".out","w",stdout);
    #endif // zxc

    solve();
}


Measured memory_bytes: 32512