program main
    implicit none
    integer n
    integer, allocatable, dimension(:) :: x
    integer i, j, d
    character s*1000000

    read(*,*) n
    read(*,*) s
    allocate(x(n))
    
    do i = 1,n
        read(s(i:i),*) x(i)
    end do

    if (n < 1000) then
        do j = 2, n
            do i = 1, n+1-j
                d = x(i) - x(i+1)
                x(i) = xor(d,rshift(d,31))-rshift(d,31)
            end do
        end do
    else
        do j = 2, 1000
            do i = 1, n+1-j
                d = x(i) - x(i+1)
                x(i) = xor(d,rshift(d,31))-rshift(d,31)
            end do
        end do

        do j = 1001, n
            do i = 1, n+1-j
                x(i) = xor(x(i),x(i+1))
            end do
        end do
    
    end if

    write(*,*) x(1)

    deallocate(x)

end program