program test_b
implicit none
    integer, allocatable, dimension(:, :):: x
    integer:: N, i, j

    read(*, *) N
    allocate(x(N, N))
    x = 0

    do j = 1, N
        read(*,*) x(1, j)
    enddo

    ! 要素が一つの場合
    if( N == 1) write(*,*) x(1, 1)

    do j = 1, N - 1
        do i = 1, N - j
            x(i, j + 1) = abs(x(i, j) - x(i + 1, j))
        enddo
    enddo

	! 答えを出力
    write(*,*) x(1, N)

stop
end program test_b