#include <bits/stdc++.h>

using namespace std;

typedef long long LL;
typedef pair<int , int> P2;
typedef pair<pair<int , int> , int> P3;
typedef pair<pair<int , int> , pair<int , int> > P4;
#define PB(a) push_back(a)
#define MP(a , b) make_pair((a) , (b))
#define M3P(a , b , c) make_pair(make_pair((a) , (b)) , (c))
#define M4P(a , b , c , d) make_pair(make_pair((a) , (b)) , make_pair((c) , (d)))
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)

const int MC = 2017;
char A[MC],B[MC];
int c[MC];
int l[MC],r[MC];
int sl[MC],sr[MC];

int main(){
	scanf("%s %s" , A , B);
	int n = 0;
	bool zeroA = 1 , zeroB = 1;
	while(B[n] != 0){
		if(A[n] == '1') zeroA = 0;
		if(B[n] == '1') zeroB = 0;
		sl[n] = sr[n] = n;
		++n;
	}
	if(zeroB){
		printf("%d\n" , zeroA ? 0 : -1);
		return 0;
	}
	repp(i,0,n) repp(j,0,n) if(A[j] != B[(i+j)%n]) ++c[i];
	repp(i,0,n){
		while(B[(i+n-l[i])%n] == '0') ++l[i];
		while(B[(i+r[i])%n] == '0') ++r[i];
	}
	sort(sl,sl+n,[&](const int p , const int q){return l[p] < l[q];});
	sort(sr,sr+n,[&](const int p , const int q){return r[p] < r[q];});
	int ans = 123456789;
	repp(i,0,n){
		int m = 0;
		int p = n-1;
		ans = min(ans , 2*n-2-i+c[(n-i)%n]);
		repm(j,n-1,i){
			while(l[sl[p]] == j){
				if(A[sl[p]] != B[(sl[p]+n-j+1)%n]) m = max(m , r[sl[p]]);
				--p;
			}
			ans = min(ans , (j-1)*2-i+c[(n-i)%n]+m*2);
		}
	}
	repp(i,0,n){
		int m = 0;
		int p = n-1;
		ans = min(ans , 2*n-2-i+c[i]);
		repm(j,n-1,i){
			while(r[sr[p]] == j){
				if(A[sr[p]] != B[(sr[p]+j-1)%n]) m = max(m , l[sr[p]]);
				--p;
			}
			ans = min(ans , (j-1)*2-i+c[i]+m*2);
		}
	}
	printf("%d\n" , ans);
	return 0;
}
