program one_two_three_triangle
  implicit none
  integer :: n, a(1000000) = 0, i, j, m = 0
  character(1000000) :: s
  logical :: f
  read(*,*) n
  read(*,*) s
  do i = 1, n
    a(i) = ichar(s(i:i)) - 48
  end do
  do i = n - 1, 1, -1
    f = .true.
    do j = 1, i
      a(j) = abs(a(j) - a(j + 1))
      if (a(j) == 2) f = .false.
    end do
    if (f) then
      n = i
      exit
    end if
    f = .false.
  end do
  if (f .and. n > 1) then
    do i = 1, n - 1
      m = m + abs(a(i) - a(i + 1))
    end do
    write(*,'(i0)') mod(m, 2)
    stop
  end if
  write(*,'(i0)') a(1)
end program one_two_three_triangle