#include #define rep(i,n) for(int i = 0; i < (n); i++) using namespace std; typedef long long ll; int main(){ cin.tie(0); ios::sync_with_stdio(0); int H,W; cin >> H >> W; vector> A(H, vector(W)); rep(i,H)rep(j,W) cin >> A[i][j]; auto h = [&](int i, int j){ return i * W + j; }; auto h_inv = [&](int v){ return pair{v / W, v % W}; }; vector> dp(H * W, vector(2, -1e18)); queue q; q.push(h(0, 0)); dp[h(0, 0)][0] = dp[h(0, 0)][1] = A[0][0]; int g = h(H - 1, W - 1); while(!q.empty()) { int from = q.front(); q.pop(); auto [ci, cj] = h_inv(from); for(int to : {h(ci + 1, cj), h(ci, cj + 1)}) { auto [i, j] = h_inv(to); if(i == H || j == W) continue; int E = A[i][j]; if(dp[from][0] > E) { dp[to][0] = max(dp[to][0], dp[from][0] + E); } else { if(to != g) dp[to][1] = max(dp[to][1], dp[from][0]); } if(dp[from][1] > E) { dp[to][1] = max(dp[to][1], dp[from][1] + E); } q.push(to); } } cout << (dp[g][0] == -1e18 && dp[g][1] == -1e18 ? "No" : "Yes") << endl; }