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

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

    x = 0

    do i = 1,n
        x(1,i) = a(i)
    end do

    do j = 2, n
        do i = 1, n+1-j
            x(j,i) = abs(x(j-1,i)-x(j-1,i+1))
        end do
    end do
    write(*,*) x(n,1)
    deallocate(x)
    deallocate(a)
end program