#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
#define pb push_back
#define pii pair < int , int >
#define F first
#define S second
#define int long long
#define sync ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#pragma GCC optimize ("Ofast")
using namespace std;
/// khodaya komak kon
/// ya navid navid
const int N=2003;
ll dp[N];
ll pd[N];
ll a[N];
ll b[N];
int32_t main(){
    string s,t;
    cin >> s >> t;
    ll n=s.size();
    ll t3=0,t4=0;
    for (int i=1;i<=n;i++){
        if (s[i-1]=='1'){
            a[i]=1;
            t3++;
        }
        if (t[i-1]=='1'){
            b[i]=1;
            t4++;
        }
    }
    if (t4==0 && t3>0){
        cout << -1;
        return 0;
    }
    ll p1=0;
    if (b[1]!=1){
        for (int i=n;i>0;i--){
            p1++;
            if (b[i]==1){
                break;
            }
        }
    }
    dp[1]=p1;
    for (int i=2;i<=n;i++){
        if (b[i]==1){
            dp[i]=0;
        }
        else{
            dp[i]=dp[i-1]+1;
        }
      //  cout << i << " km " << dp[i] << endl;
    }
    ///
    p1=0;
    if (b[n]!=1){
        for (int i=1;i<n;i++){
            p1++;
            if (b[i]==1){
                break;
            }
        }
    }
    pd[n]=p1;
    for (int i=n-1;i>0;i--){
        if (b[i]==1){
            pd[i]=0;
        }
        else{
            pd[i]=pd[i+1]+1;
        }
        //cout << i << " rf " << pd[i] << endl;
    }
    ll mi=1e9+100;
    for (int i=0;i<=n;i++){
        ll ans=0;
        for (int j=1;j<=n;j++){
            if (a[j]==0 && b[(j+i-1)%n+1]==1){
                ans++;
            }
        }
        vector <pii> p;
        p.pb({0,0});
        for (int j=1;j<=n;j++){
            if (a[j]==1 && b[(j+i-1)%n+1]==0){
                ans++;
                p.pb({dp[j],pd[j]});
            }

        }
        sort(p.begin(),p.end());
        if (i==0){
            for (int j=0;j<p.size();j++){
               // cout << p[j].F << " " << p[j].S << " " << ans << endl;
            }
        }
        ll w=1e9;
        if (p.size()==0){
            w=ans+i;
        }
        ll ma=0;
        for (int j=(ll)p.size()-1;j>-1;j--){
            ll u=max(i,i+(ma-i)*2);
            w=min(w,u+ans+2*p[j].F);

            ma=max(ma,p[j].S);
        }
        mi=min(mi,w);
      //  cout << i << " " << w << endl;
    }
    //cout << mi << endl;
    for (int i=0;i<=n;i++){
        ll ans=0;
        for (int j=1;j<=n;j++){
            ll z=j-i+n;
            z%=n;
            if (z==0){
                z=n;
            }
            if (a[j]==0 && b[z]==1){
                ans++;
            }
        }
        vector <pii> p;
        p.pb({0,0});
        for (int j=1;j<=n;j++){
            ll z=j-i+n;
            z%=n;
            if (z==0){
                z=n;
            }
            if (a[j]==1 && b[z]==0){
                ans++;
                p.pb({pd[j],dp[j]});
            }

        }
        sort(p.begin(),p.end());
        ll w=1e9;
        if (p.size()==0){
            w=ans+i;
        }
        ll ma=0;
        for (int j=(ll)p.size()-1;j>-1;j--){
            ll u=max(i,i+(ma-i)*2);
            w=min(w,u+ans+2*p[j].F);

            ma=max(ma,p[j].S);
        }
        mi=min(mi,w);
        //cout << i << " " << w << endl;

    }
    cout << mi << endl;

}


Measured memory_bytes: 384