#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <utility>
#include <queue>
#include <set>
#include <map>
#include <deque>
#include <iomanip>
#include <cstdio>
#include <stack>
#include <numeric>
#include <cassert>
using namespace std;
typedef  long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define  MP make_pair
#define  PB push_back
#define inf 1000000007
#define mod 1000000007
#define rep(i,n) for(int i=0;i<(int)(n);++i)

template<typename T> class segtree{
private:
    int n,sz;
    vector<T> node;
public:
    segtree(vector<T>& v) : sz((int)v.size()){
        n = 1;
        while(n < sz){
            n *= 2;
        }
        node.resize(2*n-1, numeric_limits<T>::min());
        for(int i = 0; i < sz; i++){
            node[i+n-1] = v[i];
        }
        for(int i=n-2; i>=0; i--){
            node[i] = max(node[i*2+1], node[i*2+2]);
        }
    }
    void update(int k,T a){
    	k += n-1;
    	node[k] = a;
    	while(k>0){
            k = (k-1)/2;
            node[k] = max(node[2*k+1],node[2*k+2]);
    	}
    }
    T query(int a,int b,int k=0,int l=0,int r=-1){
        if(r < 0) r = n;
    	if(r <= a || b <= l){
            return numeric_limits<T>::min();
    	}
    	if(a <= l && r <= b){
            return node[k];
    	}else{
            T vl = query(a,b,2*k+1,l,(l+r)/2);
            T vr = query(a,b,2*k+2,(l+r)/2,r);
            return max(vl,vr);
    	}
    }
    void print(){
        for(int i = 0; i < sz; i++){
            cout<<query(i,i+1)<< " ";
        }
        cout<<endl;
    }
};

int n;
int calc(int l,int r,vector<int>&s){
    if(l==0){
        return s[r];
    }else{
        return s[r]-s[l-1];
    }
}
int solve(string a,string b){
    //cerr << a << " " << b << endl;
    int mi = inf;
    vector<int> p;
    vector<int> s(n);
    rep(i,n){
        if(b[i]=='1'){
            p.push_back(i);
            s[i] = 1;
        }
    }
    int m = p.size();
    rep(i,m){
        p.push_back(p[i]+n);
    }
    rep(i,n-1){
        s[i+1] += s[i];
    }
    rep(id,n){
        int c = id;
        vector<pair<int,int> > d;
        for(int i=0;i<id;i++){
            if(a[i]!=b[n-(id-i)]){
                c++;
                if(calc(0,i,s)+calc(n-(id-i),n-1,s)==0){
                    int l,r;
                    auto x = lower_bound(p.begin(),p.end(),n+n-(id-i));
                    x--;
                    l = n+n-(id-i)-(*x);
                    r = (*upper_bound(p.begin(),p.end(),i))-i;
                    d.push_back(MP(l,r));
                }
            }
        }
        for(int i=id;i<n;i++){
            if(a[i]!=b[i-id]){
                c++;
                if(calc(i-id,i,s)==0){
                    int l,r;
                    auto x = lower_bound(p.begin(),p.end(),n+i-id);
                    x--;
                    l = n+i-id-(*x);
                    r = (*upper_bound(p.begin(),p.end(),i))-i;
                    d.push_back(MP(l,r));
                }
            }
        }
        sort(d.begin(),d.end());
        int mm = d.size();
        if(mm!=0){
            vector<int> q;
            for(int i=0;i<mm;i++){
                q.push_back(d[i].second);
                //cerr << d[i].first << " " << d[i].second << endl;
            }
            segtree<int> sg(q);
            int res = inf;
            res = min(res,sg.query(0,mm));
            res = min(res,d[mm-1].first);
            for(int i=0;i<mm-1;i++){
                res = min(res,d[i].first+sg.query(i+1,mm));
            }
            //cerr << id << " " << 2*res+c << " " << res << " " << c << endl;
            mi = min(mi,2*res+c);
        }else{
            //cerr << id << " " << c << endl;
            mi = min(mi,c);
        }
    }
    return mi;
}

int main(){
    string a,b;
    cin >> a >> b;
    n = a.size();
    bool flag = 1;
    rep(i,n){
        if(b[i]=='1'){
            flag = 0;
        }
    }
    if(flag){
        if(a==b){
            cout << 0 << endl;
        }else{
            cout << -1 << endl;
        }
    }else{
        int mi = inf;
        mi = min(mi,solve(a,b));
        reverse(a.begin(),a.end());
        reverse(b.begin(),b.end());
        mi = min(mi,solve(a,b));
        cout << mi << endl;
    }
    return 0;
}

Measured memory_bytes: 512