#include using namespace std; typedef long long int ll; typedef pair P; typedef vector VI; typedef vector VVI; #define REP(i,n) for(int i=0;i<(n);i++) #define ALL(v) v.begin(),v.end() template bool chmax(T &x, const T &y) {return (x bool chmin(T &x, const T &y) {return (x>y)?(x=y,true):false;}; constexpr ll MOD=998244353; constexpr ll INF=2e18; struct edge { ll to, cost; }; vector g[2000500]; vector d(2000500,INF); void dijkstra(int s){ priority_queue,greater

> que; d[s]=0; que.push({0,s}); while(!que.empty()){ P p=que.top(); que.pop(); int v=p.second; if(d[v]d[v]+e.cost){ d[e.to]=d[v]+e.cost; que.push({d[e.to],e.to}); } } } } int main(){ int n, m; cin >> n >> m; VVI a(n,VI(m)); REP(i,n)REP(j,m) cin >> a[i][j]; if(n==1){ cout << 0 << endl; return 0; } int s=2000498, t=2000499; REP(j,m) g[s].push_back({j,a[0][j]}); REP(j,m) g[(n-1)*m+j].push_back({t,0}); REP(i,n){ REP(j,m) g[i*m+j].push_back({(i+n)*m,0}); REP(j,m) g[(i+n)*m].push_back({i*m+j,a[i][j]}); if(i