program example
	implicit none

	integer(16) :: i=1,j=1,N
    integer(16),allocatable :: x(:,:),A(:)
    
    read(*,*) N
     
    allocate(x(N,N),A(N))

	do j=1,N
		read(*,"(i1)",advance="no",end=100) x(1,j)

    end do

100    do i=2,N
     
    	do j=1,N+1-i
        
        	x(i,j)=abs(x(i-1,j)-x(i-1,j+1))
        
        end do
    
    end do
    
    write(*,*) x(N,1)

end program