#include <iostream>
#include <fstream>
#include <sstream>
#include <string.h>
#include <algorithm>
#include <cmath>
#include <assert.h>
#include <stack>
#include <queue>
#include <list>
#include <vector>
#include <map>
#include <set>

//#define DEBUG 1

#define int long long
#define for0(i,n) for (int i=0; i<n; i++)
#define iter(c) for(auto it=c.begin(); it!=c.end(); it++)
#define iter2(c) for(auto it2=c.begin(); it2!=c.end(); it2++)
#define vec(x) vector< x >
#define pb push_back
#define ms(a,z) memset(a,z,sizeof(a));
#define mp make_pair
#define X first
#define Y second
#define sqr(x) 1LL*(x)*(x)
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define all(a) a.begin(),a.end()
#define sz(x) (int)(x).size()
#ifdef int
#define read(x) scanf("%lld",&x);
#else
#define read(x) scanf("%d",&x);
#endif

#ifdef DEBUG
#define nl cout<<"\n";
#define pr(x) cout<<(x)<<" ";
#define prl(x) cout<<#x " = "<<x<<endl;
#define prp(x) cout<<"("<<(x).first<<" "<<(x).second<<") ";
#define printv(v) {for(int _=0; _<sz(v); _++) cout<<v[_]<<" "; cout<<"\n";}
#define printa(a,s) {for (int _=0; _<s; _++) cout<<a[_]<<" "; cout<<"\n";}
#define print2D(a,m,n) {for (int _=0; _<m; _++) {for (int __=0; __<n; __++) cout<<a[_][__]<<" "; cout<<"\n";} cout<<"\n";}
#define debug cout<<"ok at line "<<__LINE__<<endl;
#else
#define nl
#define pr(x)
#define prl(x)
#define prp(x)
#define printv(v)
#define printa(a,s)
#define print2D(a,m,n)
#define debug
#endif
#define MAXN 2000
#define mod(x,n) ((((x)%n)+n)%n)

using namespace std;

typedef long long ll;

const int INF = 2147483647;
const long long INFL = 9223372036854775807LL;
const double EPSILON = 0.00000001;
const long long MOD = 1000000007;

int left_dist[MAXN+5], right_dist[MAXN+5]; //distance to nearest 1 in B 
int max_left_shift[MAXN+5];

int solve(string A, string B)
{
    //prl(A) prl(B)
    int n = A.length();
    for (int i=0; i<n; i++) {
        for (int j=0; j<n; j++) {
            if (B[mod(i+j,n)] == '1') {
                right_dist[i] = j;
                break;
            }
        }
        for (int j=0; j<n; j++) {
            if (B[mod(i-j,n)] == '1') {
                left_dist[i] = j;
                break;
            }
        }
    }
    //printa(right_dist,n)
    //printa(left_dist,n)
    
    int ans = INF;
    for (int goal=0; goal<n; goal++) {
        //prl(goal)
        //vector<int> flip_pos;
        vector<pair<int,int>> shift_dists;
        for (int i=0; i<n; i++) {
            if (A[i] != B[mod(i+goal,n)]) {
                //flip_pos.pb(i);
                shift_dists.pb(mp(right_dist[i], left_dist[i]));
            }
        }
        sort(all(shift_dists));
        //iter(shift_dists) { prp(*it) } nl
        
        int m = sz(shift_dists);
        if (m == 0) {
            ans = min(ans,min(goal,n-goal));
        }
        
        max_left_shift[m] = 0;
        for (int i=m-1; i>=0; i--) {
            max_left_shift[i] = max(max_left_shift[i+1], shift_dists[i].second);
        }
        for (int i=0; i<m; i++) {
            int r = shift_dists[i].first;
            int l = max_left_shift[i+1];
            //pr(r) pr(l) 
            int sol1 = m + l + (r+l) + fabs(r-goal);
            //pr(sol1)
            ans = min(ans,sol1);
            
            int sol2 = m + 2*r + l + fabs(n-l-goal); 
            //pr(sol2)
            ans = min(ans,sol2);
            //nl
        }        
        //nl
    }    
    return ans;
}

bool check_one(string s)
{
    for0(i,s.length()) {
        if (s[i] == '1')
            return true;
    }
    return false;
}

int32_t main()
{
    #ifdef DEBUG
    freopen("shift_and_flip.txt","r",stdin);
    //freopen("","w",stdout);
    #endif

    string A,B;
    cin >> A;
    cin >> B;
    //corner case - check if B is all zeros 
    if (not check_one(B)) {
        if (check_one(A))
            cout<<-1<<endl;
        else 
            cout<<0<<endl;
        return 0;
    }
    
    int sol1 = solve(A,B);
    reverse(all(A));
    reverse(all(B));
    int sol2 = solve(A,B);
    cout<<min(sol1,sol2)<<endl;
    return 0;
}


Measured memory_bytes: 512