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

    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

    write(*,*) x(1)

    deallocate(x)

end program