#include "bits/stdc++.h"
using namespace std;
const int N = 2e3 + 3;
int n;
char a[N];
char b[N];
int ones[N];
int zeroes[N];
int changes[N];
int siz;
int lft[N];
int rgt[N];
int get(int l , int r){
	if(l == 0){
		return ones[r];
	}
	if(l <= r){
		return ones[r] - ones[l - 1];
	}
	return ones[n - 1] - ones[l - 1] + ones[r];
}
int moveleft[N];
int moveright[N];
pair < int , int > arr1[N];
pair < int , int > arr2[N];
int idx1[N];
int idx2[N];
bool done[N];
int ans;
int solveright(int move){
	int res = 0;
	siz = 0;
	for(int i = 0 ; i < n ; ++i){
		int who = (i + n - move) % n;
		if(a[who] != b[i]){
			if(!get(who , i)){
				changes[++siz] = i;
			}
			++res;
		}
	}
	if(!siz){
		return res;
	}
	for(int i = 1 ; i <= siz ; ++i){
		int idx = changes[i];
		if(rgt[idx] == n){
			moveright[i] = n - idx + rgt[0];
		}
		else{
			moveright[i] = rgt[idx] - idx;
		}
		int l = (idx - move + n) % n;
		if(lft[l] == -1){
			moveleft[i] = l + n - lft[n - 1];
		}
		else{
			moveleft[i] = l - lft[l];
		}
	}
	for(int i = 1 ; i <= siz ; ++i){
		arr1[i] = make_pair(moveleft[i] * 2 , i);
		arr2[i] = make_pair(moveright[i] * 2 , i);
	}
	sort(arr1 + 1 , arr1 + 1 + siz);
	sort(arr2 + 1 , arr2 + 1 + siz);
	for(int i = 1 ; i <= siz ; ++i){
		idx1[arr1[i].second] = i;
		idx2[arr2[i].second] = i;
		done[i] = 0;
	}
	done[0] = 0;
	int ptr = siz;
	int add = 1e9;
	add = min(add , arr2[siz].first);
	arr2[0].first = 0;
	for(int i = 1 ; i <= siz ; ++i){
		done[idx2[arr1[i].second]] = 1;
		while(done[ptr]){
			--ptr;
		}
		add = min(add , arr1[i].first + arr2[ptr].first);
	}
	return res + add;
}
int solveleft(int move){
	int res = 0;
	siz = 0;
	for(int i = 0 ; i < n ; ++i){
		int who = (i + move) % n;
		if(a[who] != b[i]){
			if(!get(i , who)){
				changes[++siz] = who;
			}
			++res;
		}
	}
	if(!siz){
		return res;
	}
	for(int i = 1 ; i <= siz ; ++i){
		int idx = changes[i];
		if(rgt[idx] == n){
			moveright[i] = n - idx + rgt[0];
		}
		else{
			moveright[i] = rgt[idx] - idx;
		}
		int l = (idx - move + n) % n;
		if(lft[l] == -1){
			moveleft[i] = l + n - lft[n - 1];
		}
		else{
			moveleft[i] = l - lft[l];
		}
	}
	for(int i = 1 ; i <= siz ; ++i){
		arr1[i] = make_pair(moveleft[i] * 2 , i);
		arr2[i] = make_pair(moveright[i] * 2 , i);
	}
	sort(arr1 + 1 , arr1 + 1 + siz);
	sort(arr2 + 1 , arr2 + 1 + siz);
	for(int i = 1 ; i <= siz ; ++i){
		idx1[arr1[i].second] = i;
		idx2[arr2[i].second] = i;
		done[i] = 0;
	}
	done[0] = 0;
	int ptr = siz;
	int add = 1e9;
	add = min(add , arr2[siz].first);
	arr2[0].first = 0;
	for(int i = 1 ; i <= siz ; ++i){
		done[idx2[arr1[i].second]] = 1;
		while(done[ptr]){
			--ptr;
		}
		add = min(add , arr1[i].first + arr2[ptr].first);
	}
	return res + add;
}

int main(){
	scanf("%s" , a);
	scanf("%s" , b);
	n = strlen(a);
	ones[0] = b[0] == '1';
	zeroes[0] = b[0] == '0';
	bool rip = a[0] == '1';
	for(int i = 1 ; i < n ; ++i){
		ones[i] = ones[i - 1] + (b[i] == '1');
		zeroes[i] = zeroes[i - 1] + (b[i] == '0');
		rip |= a[i] == '1';
	}
	if(rip && ones[n - 1] == 0){
		printf("-1\n");
		return 0;
	}
	if(b[0] == '1'){
		lft[0] = 0;
	}
	else{
		lft[0] = -1;
	}
	for(int i = 1 ; i < n ; ++i){
		if(b[i] == '1'){
			lft[i] = i;
		}
		else{
			lft[i] = lft[i - 1];
		}
	}
	rgt[n] = n;
	for(int i = n - 1 ; i >= 0 ; --i){
		if(b[i] == '1'){
			rgt[i] = i;
		}
		else{
			rgt[i] = rgt[i + 1];
		}
	}
	ans = 1e9;
	for(int i = 0 ; i < n ; ++i){
		ans = min(ans , solveleft(i) + i);
	}
	for(int i = 1 ; i < n ; ++i){
		ans = min(ans , solveright(i) + i);
	}
	printf("%d\n" , ans);
}

Measured memory_bytes: 384