import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.stdio;
import std.string;
import std.typecons;

immutable int NA = -1;

int solve (bool [] a, bool [] b)
{
	if (!any (b))
	{
		return (any (a)) ? NA : 0;
	}
	auto n = a.length.to !(int);

	auto b5 = b ~ b ~ b ~ b ~ b;
	auto lo = new int [n];
	auto hi = new int [n];
	foreach (i; 0..n)
	{
		if (a[i])
		{
			int p = i;
			while (!b5[p + n * 2])
			{
				p -= 1;
			}
			lo[i] = i - p;

			int q = i;
			while (!b5[q + n * 2])
			{
				q += 1;
			}
			hi[i] = q - i;
		}
		else
		{
			lo[i] = int.max;
			hi[i] = int.max;
		}
	}
	debug {writeln ("lo = ", lo);}
	debug {writeln ("hi = ", hi);}

	alias Pair = Tuple !(int, q{x}, int, q{y});

	int res = int.max / 2;
	foreach (delta; 0 - n * 1..1 + n * 1)
	{
		int cur = abs (delta);
		Pair [] p;
		foreach (i; 0..n)
		{
			int ca = a[i];
			int cb = b5[i + delta + n * 2];
			if (ca && !cb)
			{
				int clo = lo[i];
				if (delta < 0)
				{
					clo = max (0, clo - abs (delta));
				}
				int chi = hi[i];
				if (delta > 0)
				{
					chi = max (0, chi - abs (delta));
				}
				p ~= Pair (clo, chi);
				cur += 1;
			}
			if (!ca && cb)
			{
				cur += 1;
			}
		}

		sort (p);
		debug {writeln (delta, ": ", cur, ", ", p);}
		int maxLo = (p.empty) ? 0 : p[$ - 1].x;
		int maxHi = 0;
		int add = maxLo + maxHi;
		while (!p.empty)
		{
			maxHi = max (maxHi, p.back.y);
			p.popBack ();
			maxLo = (p.empty) ? 0 : p[$ - 1].x;
			add = min (add, maxLo + maxHi);
		}
		res = min (res, cur + add * 2);
		debug {writeln ("res = ", res);}
	}

	return res;
}

void main ()
{
	string s;
	while ((s = readln.strip) != "")
	{
		string t = readln.strip;
		auto a = s.map !(q{a == '1'}).array;
		auto b = t.map !(q{a == '1'}).array;
		writeln (solve (a, b));
	}
}
