program one_two_three_triangle
  implicit none
  integer :: n, m, i
  integer, dimension(0:1000001) :: a = 0, f = 0
  character(1000000) :: s
  read(*,*) n
  read(*,*) s
  do i = 1, n
    a(i) = ichar(s(i:i)) - 49
    f(i + 1) = f(i)
    m = i + 1
    do while (.not.btest(m, 0))
      f(i + 1) = f(i + 1) + 1
      m = rshift(m, 1)
    end do
  end do
  m = 0
  do i = 1, n
    m = m + a(i) * (f(n + 1) - f(i) - f(n - i + 1))
  end do
  if (btest(m, 0)) then
    write(*,'(i0)') 1
    stop
  end if
  if (any(a(1:n) == 1)) then
    write(*,'(i0)') 0
    stop
  end if
  a(1:n) = a(1:n) / 2
  m = 0
  do i = 1, n
    m = m + a(i) * (f(n + 1) - f(i) - f(n - i + 1))
  end do
  if (btest(m, 0)) then
    write(*,'(i0)') 2
    stop
  end if
  write(*,'(i0)') 0
end program one_two_three_triangle