program main
    implicit none
    integer n
    integer, allocatable, dimension(:) :: x
    integer i, j, flag
    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
            x(i) = x(i) - x(i+1)
            if(x(i) < 0) then
                x(i) = x(i)*(-1)
            end if
        end do
    end do

    write(*,*) x(1)

    deallocate(x)

end program