#include using namespace std; typedef long long ll; typedef pair P; typedef pair Q; #define REP(i,n) for(int i=0;i> H >> W; vector v; for(i=1;i<=H;i++) for(j=1;j<=W;j++){ int a; cin >> a; v.push_back(Q(a,P(i,j))); } sort(v.begin(),v.end()); vector dp(H*W,1); REP(i,H*W){ for(j=i+1;j