import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop;



void main() {
    auto A = readln.chomp.map!(x => x == '1').array;
    auto B = readln.chomp.map!(x => x == '1').array;
    auto N = A.length.to!int;

    if (A.any && B.map!(b => !b).all) {
        writeln(-1);
        return;
    }

    auto L = new int[](N);
    auto R = new int[](N);

    foreach (i; 0..N) {
        foreach (j; 0..N) {
            if (B[((i-j)%N+N)%N]) {
                L[i] = j;
                break;
            }
        }
        foreach (j; 0..N) {
            if (B[(i+j)%N]) {
                R[i] = j;
                break;
            }
        }
    }


    int ans = 1 << 29;

    foreach (i; 0..N) { // A[i]を先頭にする
        int tmp = 0;
        Tuple!(int, int)[] LR;

        foreach (j; 0..N) {
            int k = (i + j) % N;
            if (B[j] != A[k]) {
                tmp++;
                LR ~= tuple(L[k], R[k]);
            }
        }

        LR.sort!"a[0] < b[0]";
        int M = LR.length.to!int;

        auto r_max = new int[](M);
        r_max[$-1] = LR[$-1][1];

        for (int j = M - 2; j >= 0; j--) {
            r_max[j] = max(LR[j][1], r_max[j+1]);
        }

        foreach (j; 0..M) {
            int left = LR[j][0];
            int right = j < M - 1 ? LR[j+1][1] + left : 0;
            int pos = abs(left - right) + i;
            pos = min(pos, N - pos);
            ans = min(ans, left + right + pos + tmp);
        }
    }

    ans.writeln;
}
