#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <string.h>
#include <fstream>
#include <assert.h>

using namespace std;


#define LL long long
#define N 201000
#define M 10000100
#define MP make_pair
#define Pi acos(-1.0)
//#pragma comment(linker,"/S    TACK:1024000000,1024000000")
#define ls (rt << 1)
#define rs (ls | 1)
#define md ((ll+rr)/2)
#define lson ls,ll,md
#define rson rs,md+1,rr
#define mod 1000000007
#define inf 0x7fffffff
#define sqr(x) ((x)*(x))
#define eps 1e-6
#define ULL unsigned long long
LL powmod(LL a,LL b) {LL res=1;a%=mod;for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
#define F(x) ((x)/3+((x)%3 == 1 ? 0 : tb))
#define G(x) ((x)<tb ? (x)*3+1 : ((x) - tb)*3+2)
#define lowbit(x) ((x)&(-x))
#define fi first
#define se second
#define pii pair<int,int>
#define pil pair<int,LL>
#define pli pair<LL,int>
#define pb push_back
#define sf(n) scanf("%d", &n)
#define ss set<int>::iterator

int gcd(int x,int y){
    while(y){
        int t = x % y;
        x = y;
        y = t;
    }
    return x;
}

template<typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }

namespace FastIO {
#define BUF_SIZE 100000 //缓冲区大小可修改
    bool IOError = 0; //IOError == false 时表示处理到文件结尾
    inline char NextChar() {
        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 c) {
        return c == ' ' || c == '\n' || c == '\r' || c == '\t';
    }
    
    inline void read(int &x){
        bool sign=0; char ch=NextChar(); x=0;
        for (;Blank(ch);ch=NextChar());
        if (IOError)return;
        if (ch=='-')sign=1,ch=NextChar();
        for (;ch>='0'&&ch<='9';ch=NextChar())x=x*10+ch-'0';
        if (sign)x=-x;
    }
    inline void read(long long &x){
        bool sign=0; char ch=NextChar(); x=0;
        for (;Blank(ch);ch=NextChar());
        if (IOError)return;
        if (ch=='-')sign=1,ch=NextChar();
        for (;ch>='0'&&ch<='9';ch=NextChar())x=x*10+ch-'0';
        if (sign)x=-x;
    }
    inline void read(double &x){
        bool sign=0; char ch = NextChar(); x=0;
        for (;Blank(ch);ch = NextChar());
        if (IOError)return;
        if (ch=='-')sign=1,ch=NextChar();
        for (;ch>='0'&&ch<='9';ch=NextChar())x=x*10+ch-'0';
        if (ch=='.'){
            double tmp=1; ch=NextChar();
            for (;ch>='0'&&ch<='9';ch=NextChar())tmp/=10.0,x+=tmp*(ch-'0');
        }
        if (sign)x=-x;
    }
    inline void read(char *s){
        char ch=NextChar();
        for (;Blank(ch);ch=NextChar());
        if (IOError)return;
        for (;!Blank(ch)&&!IOError;ch=NextChar())*s++=ch;
        *s=0;
    }
    inline void read(char &c){
        for (c=NextChar();Blank(c);c=NextChar());
        if (IOError){c=-1;return;}
    }
}
using namespace FastIO;

int a[N], b[N];
char s[N];
int ll[N], rr[N];
pii c[N];

int main()
{
    read(s);
    int n = strlen(s);
    for(int i = 0; i < n; i++)
    {
        a[i] = (s[i] == '1');
    }
    read(s);
    for(int i = 0; i < n; i++)
    {
        b[i] = (s[i] == '1');
    }
    bool equal = 1, zero = 1;
    for(int i = 0; i < n; i++)
        equal &= (a[i] == b[i]), zero &= (b[i] == 0);
    if(equal)
    {
        puts("0");
        return 0;
    }
    if(zero)
    {
        puts("-1");
        return 0;
    }
    
    rr[n] = inf;
    for(int i = n - 1; i >= 0; i--)
    {
        rr[i] = rr[i + 1];
        if(b[i] == 1)
            rr[i] = i;
    }
    
    for(int i = n - 1; i >= 0 && rr[i] == inf; i--)
    {
        rr[i] = rr[0] + n;
    }
    
    ll[0] = (b[0] == 1 ? 0 : inf);
    for(int i = 1; i < n; i++)
    {
        ll[i] = ll[i - 1];
        if(b[i] == 1)
            ll[i] = i;
    }
    
    for(int i = 0; i < n && ll[i] == inf; i++)
    {
        ll[i] = ll[n - 1] - n;
    }
    int ans = inf;
    for(int fckn = -n; fckn <= n; fckn++)
    {
        int res = abs(fckn);
        int tt = 0;
        for(int i = 0; i < n; i++)
        {
            int ni = (i + fckn + n) % n;
            if(a[i] == b[ni]) continue;
            res++;
            if(fckn <= 0)
            {
                if(i - ll[i] <= -fckn) continue;
                c[tt].fi = ni - ll[ni];
                c[tt].se = rr[i] - i;
                tt++;
            }
            else
            {
                if(rr[i] - i <= fckn) continue;
                c[tt].fi = i - ll[i];
                c[tt].se = rr[ni] - ni;
                tt++;
            }
        }
        c[tt++] = {0,0};
        sort(c, c + tt);
        int mi = c[tt - 1].fi, mx = 0;
        
        for(int i = tt - 1; i >= 1; i--)
        {
            chkmax(mx, c[i].se);
            chkmin(mi, mx + c[i - 1].fi);
        }
        chkmin(ans, res + 2 * mi);
    }
    
    printf("%d\n",ans);
    
    return 0;
}

Measured memory_bytes: 2432