implicit none integer(8) a,b,i integer(8),allocatable :: x(:,:) read(*,*) a read(*,*) b allocate (x(1:b,1:2)) do i=1,b read(*,*) x(i,1),x(i,2) if (x(i,1)==a) then a=x(i,2) end if end do write(*,*) a end