program one_two_three_triangle
  implicit none
  integer :: n, a(1000000) = 0, m, i, j
  character(1000000) :: s
  logical :: f = .false.
  read(*,*) n
  read(*,*) s
  do i = 1, n
    a(i) = ichar(s(i:i)) - 49
    if (a(i) == 1) f = .true.
  end do
  do i = 1, n
    if (a(i) == 2) a(i) = merge(0, 1, f)
  end do
  do i = 31, 0, -1
    if (.not.btest(n - 1, i)) cycle
    m = lshift(1, i)
    n = n - m
    do j = 1, n
      a(j) = xor(a(j), a(j + m))
    end do
  end do
  write(*,'(i0)') a(1) * merge(1, 2, f)
end program one_two_three_triangle