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))
    
    do i = 1,n
        read(s(i:i),*) a(i)
    end do

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

    do j = 2, n
        do i = 1, n+1-j
            x(i) = abs(x(i)-x(i+1))
        end do
    end do

    write(*,*) x(1)

end program