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

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

    do j = 2, n
        if(mod(j,2) == 0) then
            do i = 1, n+1-j
                x(2,i) = abs(x(1,i)-x(1,i+1))
            end do
            flag = 2
        else
            do i = 1, n+1-j
                x(1,i) = abs(x(2,i)-x(2,i+1))
            end do
            flag = 1
        end if
    end do

    if (flag == 1) then
        write(*,*) x(1,1)
    else if(flag == 2) then
        write(*,*) x(2,1)
    end if

end program