#include<stdio.h>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<cstdlib>
#define N 200005
#define lowbit(o) o&(-o)
using namespace std;
int i,j,l,s,n,m,R[N],L[N],st[N],ans,mx[N],top;
int a[N],b[N];
char c[N];
inline bool cmp(int x,int y) {
	return R[x]<R[y];
}
int main() {
	scanf("%s",c+1);
	n=strlen(c+1);
	for (i=1;i<=n;i++) a[i]=c[i]-48,L[i]=R[i]=100000000;
	scanf("%s",c+1);
	for (i=1;i<=n;i++) b[i]=c[i]-48;
	for (i=1;i<=n;i++) for (j=1;j<=n;j++) if (b[j]) L[i]=min(L[i],(i-j+n)%n),R[i]=min(R[i],(j-i+n)%n);
	ans=100000000;
	for (i=1;i<=n;i++) {
		top=0; int now=i;
		for (j=1;j<=n;j++) {
			if (a[now]!=b[j]) st[++top]=now;
			now%=n; now++;
		}//printf("%d\n\n",j);
		sort(st+1,st+1+top,cmp);
		mx[top+1]=0;
		for (j=top;j;j--) mx[j]=max(mx[j+1],L[st[j]]);
		
		for (j=0;j<=top;j++) {
			//workL:
			ans=min(ans,(R[st[j]]+max((i-(n+1)+n)%n,mx[j+1]))*2-(i-(n+1)+n)%n+top);
			//workR:
			ans=min(ans,(mx[j+1]+max(((n+1)-i+n)%n,R[st[j]]))*2-((n+1)-i+n)%n+top);
		}
	}
	if (ans>=100000000) ans=-1;
	printf("%d\n",ans);
}