program shift_and_flip
  implicit none
  character(2000) :: a, b
  integer :: n, x(2000) = 0, y(2000) = 0, i, ans = 1e9
  read(*,*) a
  read(*,*) b
  n = len_trim(a)
  do i = 1, n
    if (a(i:i) == "1") x(i) = 1
    if (b(i:i) == "1") y(i) = 1
  end do
  if (all(y(1:n) == 0)) then
    if (any(x(1:n) == 1)) then
      write(*,'(i0)') -1
    else
      write(*,'(i0)') 0
    end if
    stop
  end if
  call solve()
  x(1:n) = x(n:1:-1)
  y(1:n) = y(n:1:-1)
  call solve()
  write(*,'(i0)') ans
contains
  integer function idx(i)
    integer, intent(in) :: i
    idx = modulo(i-1,n)+1
  end
  subroutine solve()
    integer :: i, j, l(n), r(n), m(0:n-1), cnt, tmp
    cnt = 0
    do i = 1, n
      l(i) = 0
      do while (y(idx(i-l(i))) == 0)
        l(i) = l(i)+1
      end do
      r(i) = 0
      do while (y(idx(i+r(i))) == 0)
        r(i) = r(i)+1
      end do
    end do
    do i = 0, n-1
      m = 0
      cnt = 0
      do j = 1, n
        if (x(j) /= y(idx(j+i))) then
          m(l(j)) = max(m(l(j)),r(j))
          cnt = cnt+1
        end if
      end do
      tmp = 0
      do j = n-1, 0, -1
        ans = min(ans,2*j+tmp+abs(tmp-i)+cnt)
        tmp = max(tmp,m(j))
      end do
    end do
  end
end program shift_and_flip