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) else if (x(i,2)==a) then a=x(i,1) end if end do write(*,*) a end