#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> 

using namespace std;

#define _int64 long long

char s1[2100];
char s2[2100];

int d[2100];

int nel[2100];
int ner[2100];

int lowbit(int x)
{
  return (x^(x&(x-1)));
}

void add2(int x)
{
  int i;
  for (i=x;i<2100;i+=lowbit(i))
    d[i]++;
}

void add1(int x)
{
  add2(x+1);
}

int get2(int x)
{
  int ret,i;
  ret=0;
  for (i=x;i>0;i-=lowbit(i))
    ret+=d[i];
  return ret;
}

int get1(int x)
{
  return get2(x+1);
}

int main()
{
  vector<pair<int,int> > a;
  int i,j,n,cnt,ll,rr,pre,tmp1,tmp2,tmp,ans,b1,b2,ma,best;
  scanf("%s%s",s1,s2);
  n=strlen(s1);
  b1=1;
  for (i=0;i<n;i++)
    if (s2[i]!='0') b1=0;
  if (b1==1)
  {
    b2=1;
    for (i=0;i<n;i++)
      if (s1[i]!='0') b2=0;
    if (b2==1) printf("0\n");
    else printf("-1\n");
    return 0;
  }
  for (i=0;i<n;i++)
    if (s2[i]=='1') break;
  ner[i]=i;
  pre=i;
  j=i-1;
  if (j<0) j+=n;
  while (j!=i)
  {
    if (s2[j]=='1') pre=j;
    ner[j]=pre;
    j--;
    if (j<0) j+=n;
  }
  
  nel[i]=i;
  pre=i;
  j=i+1;
  if (j>=n) j-=n;
  while (j!=i)
  {
    if (s2[j]=='1') pre=j;
    nel[j]=pre;
    j++;
    if (j>=n) j-=n;
  }

  memset(d,0,sizeof(d));
  for (i=0;i<n;i++)
    if (s2[i]=='1')
    {
      add1(i);
    }
  ans=2000000000;
  for (i=0;i<n;i++)
  {
    tmp=i;
    a.clear();
    for (j=0;j<n;j++)
    {
      ll=j;rr=j+i;
      if (rr>=n) rr-=n;
      if (rr>=ll)
      {
        cnt=get1(rr)-get1(ll-1);
      }
      else
      {
        cnt=get1(n)-get1(ll-1)+get1(rr);
      }
      if (s1[ll]!=s2[rr]) tmp++;
      if ((s1[ll]=='1')&&(s2[rr]=='0')&&(cnt==0))
      {
        tmp1=ll-1;
        if (tmp1<0) tmp1+=n;
        tmp1=ll-nel[tmp1];
        if (tmp1<0) tmp1+=n;
        
        tmp2=rr+1;
        if (tmp2>=n) tmp2-=n;
        tmp2=ner[tmp2]-rr;
        if (tmp2<0) tmp2+=n;
        a.push_back(make_pair(tmp1,tmp2));
      }
    }
    sort(a.begin(),a.end());
    reverse(a.begin(),a.end());
    ma=0;
    best=2000000000;
    for (j=0;j<a.size();j++)
    {
      if (a[j].first+ma<best) best=a[j].first+ma;
      if (a[j].second>ma) ma=a[j].second;
    }
    if (ma<best) best=ma;
    tmp+=best+best;
    if (tmp<ans) ans=tmp;


    tmp=n-i;
    a.clear();
    for (j=0;j<n;j++)
    {
      ll=j+i;rr=j;
      //cout<<ll<<" "<<rr<<endl;
      if (ll>=n) ll-=n;
      if (rr>ll)
      {
        cnt=get1(rr)-get1(ll-1);
      }
      else
      {
        cnt=get1(n)-get1(ll-1)+get1(rr);
      }
      if (s2[ll]!=s1[rr]) tmp++;
      if ((s2[ll]=='0')&&(s1[rr]=='1')&&(cnt==0))
      {
        tmp1=ll-1;
        if (tmp1<0) tmp1+=n;
        tmp1=ll-nel[tmp1];
        if (tmp1<0) tmp1+=n;
        
        tmp2=rr+1;
        if (tmp2>=n) tmp2-=n;
        tmp2=ner[tmp2]-rr;
        if (tmp2<0) tmp2+=n;
        //cout<<"tmp1:"<<tmp1<<" "<<tmp2<<endl;
        a.push_back(make_pair(tmp1,tmp2));
      }
    }
    //cout<<"tmp:"<<i<<" "<<tmp<<endl;
    sort(a.begin(),a.end());
    reverse(a.begin(),a.end());
    ma=0;
    best=2000000000;
    for (j=0;j<a.size();j++)
    {
      if (a[j].first+ma<best) best=a[j].first+ma;
      if (a[j].second>ma) ma=a[j].second;
    }
    if (ma<best) best=ma;
    //cout<<i<<" "<<tmp<<" "<<best<<endl;
    tmp+=best+best;
    if (tmp<ans) ans=tmp;
  }
  printf("%d\n",ans);
  return 0;
}

Measured memory_bytes: 256