# include <bits/stdc++.h>
 
/*
// ordered_set 
# include <ext/pb_ds/assoc_container.hpp>
# include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
# define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
*/
 
using namespace std;
 
typedef long long                                        ll;
typedef long double                                      ld;
typedef pair <int, int>                                  pii;
typedef pair <pii, int>                                  ppi;
typedef pair <int, pii>                                  pip;
typedef pair <pii, pii>                                  ppp;
typedef pair <ll, ll>                                    pll;
 
# define A                                               first
# define B                                               second
# define endl                                            '\n'
# define sep                                             ' '
# define all(x)                                          x.begin(), x.end()
# define kill(x)                                         return cout << x << endl, 0
# define SZ(x)                                           int(x.size())
# define Sort(x)                                         sort(all(x))
# define InTheNameOfGod                                  ios::sync_with_stdio(0);cin.tie(0); cout.tie(0);
 
ll power(ll a, ll b, ll md) {return (!b ? 1 : (b & 1 ? a * power(a * a % md, b / 2, md) % md : power(a * a % md, b / 2, md) % md));}

const int xn = 2e3 + 10;
const int xm = - 20 + 10;
const int SQ = 320;
const int sq = 320 + 10;
const int inf = 1e9 + 10;
const ll INF = 1e18 + 10;
const int mod = 1e9 + 7;
const int TM = 3;
const int base = 257;

int n, f[2][xn], ans = inf, ptr, last;
string a, b;
vector <pii> vec;

bool cmp1(pii i, pii j){ return f[0][i.A] < f[0][j.A];}
bool cmp2(pii i, pii j){ return f[1][i.A] < f[1][j.A];}

int main(){
    InTheNameOfGod;
    
	cin >> a >> b;
	n = a.size();
	for (int i = 0; i < n; ++ i){
		f[0][i] = f[1][i] = inf;
		for (int j = n - 1; j >= 0; -- j){
			if (b[(i + j) % n] == '1') f[0][i] = j;
			if (b[(i - j + n) % n] == '1') f[1][i] = j;
		}
	}
	for (int i = 0; i < n; ++ i){
		vec.clear();
		for (int j = 0; j < n; ++ j) if (a[j] != b[(i + j) % n]) vec.push_back({j, 0});
		sort(all(vec), cmp1);
		last = 0;
		for (int j = vec.size() - 1; j >= 0; -- j){
			vec[j].B = f[1][vec[j].A];
			vec[j].B = max(vec[j].B, last);
			last = vec[j].B;
		}
		ptr = 0;
		for (int j = i; j < n; ++ j){
			while (ptr < vec.size() && f[0][vec[ptr].A] <= j) ++ ptr;
			if (ptr == vec.size()){
				ans = min(ans, j + j - i + SZ(vec));
				break;
			}
			ans = min(ans, j + j - i + 2 * vec[ptr].B + SZ(vec));
		}
		vec.clear();
		for (int j = 0; j < n; ++ j) if (a[j] != b[(j - i + n) % n]) vec.push_back({j, 0});
		sort(all(vec), cmp2);
		last = 0;
		for (int j = vec.size() - 1; j >= 0; -- j){
			vec[j].B = f[0][vec[j].A];
			vec[j].B = max(vec[j].B, last);
			last = vec[j].B;
		}
		ptr = 0;
		for (int j = i; j < n; ++ j){
			while (ptr < vec.size() && f[1][vec[ptr].A] <= j) ++ ptr;
			if (ptr == vec.size()){
				ans = min(ans, j + j - i + SZ(vec));
				break;
			}
			ans = min(ans, j + j - i + 2 * vec[ptr].B + SZ(vec));
		}
	}
	if (ans >= inf) kill(- 1);
	cout << ans << endl;
	
    return 0;
}


Measured memory_bytes: 3716