module mod implicit none integer::m(100,100) integer::h,w logical::vis(100,100) contains recursive logical function dfs(curh,curw,preh,prew)result(ret) integer,intent(in)::curh,curw,preh,prew integer::dh(4)=[1,-1,0,0],dw(4)=[0,0,1,-1] integer::i,j,k,l,x,y,z ret=.false. vis(curh,curw)=.true. do i=1,4 y=curh+dh(i) x=curw+dw(i) if(.not.(1<=x.and.x<=w.and.1<=y.and.y<=h))cycle if(y==preh.and.x==prew)cycle if(m(curh,curw)/=m(y,x))cycle if(vis(y,x))then ret=.true. else ret=ret.or.dfs(y,x,curh,curw) end if end do end function end module program main use mod implicit none integer::i,j,k,l,n,x,y,z logical::ans=.false. read(*,*)w,h do i=1,h read(*,*)(m(i,j),j=1,w) end do do i=1,h do j=1,w vis(i,j)=.false. end do end do do i=1,h do j=1,w if(vis(i,j))cycle ans=ans.or.dfs(i,j,-1,-1) end do end do if(ans)then print*,"possible" else print*,"impossible" end if end program