#include<cstring>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<assert.h>
#include<ctime>
using namespace std;
#define LL long long
const int maxn = 2e5+10;
const int maxm = 1e5+10;
double pi = acos(-1.0);

//struct edge{
//    int from, to, cost, next;
//}e[maxn*2];
//int head[maxn], tot;
//inline void add(int a, int b, int c) {
//    e[tot].from = a, e[tot].to = b, e[tot].cost = c, e[tot].next = head[a], head[a] = tot++;
//}
//namespace fastIO {
//    #define BUF_SIZE 100000
//    //fread -> read
//    bool IOerror = 0;
//    inline char nc() {
//        static char buf[BUF_SIZE], *p1 = buf + BUF_SIZE, *pend = buf + BUF_SIZE;
//        if(p1 == pend) {
//            p1 = buf;
//            pend = buf + fread(buf, 1, BUF_SIZE, stdin);
//            if(pend == p1) {
//                IOerror = 1;
//                return -1;
//            }
//        }
//        return *p1++;
//    }
//    inline bool blank(char ch) {
//        return ch == ' ' || ch == '\n' || ch == '\r' || ch == '\t';
//    }
//    inline void read(int &x) {
//        char ch;
//        while(blank(ch = nc()));
//        if(IOerror)
//            return;
//        for(x = ch - '0'; (ch = nc()) >= '0' && ch <= '9'; x = x * 10 + ch - '0');
//    }
//    #undef BUF_SIZE
//};
//using namespace fastIO;

char s1[maxn], s2[maxn];
int l[maxn], r[maxn];
int c[maxn], ll[maxn], rr[maxn];
bool cmp1(int a, int b) {
    return l[a] < l[b];
}
bool cmp2(int a, int b) {
    return r[a] < r[b];
}
int main(){
    while(~scanf("%s%s", s1, s2)) {
        int len = strlen(s1);
        bool a = 1, b = 1;
        for(int i = 0; i < len; i++) {
            if(s1[i]-'1' == 0) a = 0;
            if(s2[i]-'1' == 0) b = 0;
            ll[i] = rr[i] = i;
        }
        if(b) {
            printf("%s\n", a ? "0":"-1");
            continue;
        }
        for(int i = 0; i < len; i++) {
            c[i] = l[i] = r[i] = 0;
            for(int j = 0; j < len; j++) {
                if(s1[j] != s2[(i+j)%len]) c[i]++;
            }
        }
        for(int i = 0; i < len; i++) {
            while(s2[(i+len-l[i])%len] == '0') l[i]++;
            while(s2[(i+r[i])%len] == '0') r[i]++;
        }
        sort(ll, ll+len, cmp1);
        sort(rr, rr+len, cmp2);
        int ans = 2e9;
        for(int i = 0; i < len; i++) {//shift right i
            int m = 0, p = len-1;
            ans = min(ans, 2*len-2-i+c[(len-i)%len]);//the cost of s1 shift right len-1 and shift right
            for(int j = len-1; j > i; j--) {
                while(l[ll[p]] == j) {//can't reach, shift left first
                    if(s1[ll[p]] != s2[(ll[p]+len-j+1)%len]) m = max(m, r[ll[p]]);
                    p--;
                }
                ans = min(ans, (j-1)*2-i+c[(len-i)%len]+m*2);
            }
        }
        for(int i = 0; i < len; i++) {
            int m = 0, p = len-1;
            ans = min(ans, 2*len-2-i+c[i]);
            for(int j = len-1; j > i; j--) {
                while(r[rr[p]] == j) {
                    if(s1[rr[p]] != s2[(rr[p]+j-1)%len]) m = max(m, l[rr[p]]);
                    p--;
                }
                ans = min(ans, (j-1)*2-i+c[i]+m*2);
            }
        }
        printf("%d\n", ans);
    }
}


Measured memory_bytes: 2304