1 #include<cstdio>
2
3 #include<cstdlib>
4
5 #include<cmath>
6
7 #include<cstring>
8
9 #include<algorithm>
10
11 #include<iostream>
12
13 #include<vector>
14
15 #include<map>
16
17 #include<set>
18
19 #include<queue>
20
21 #include<string>
22
23 #define inf 1000000000
24
25 #define maxn 105
26
27 #define maxm 500+100
28
29 #define eps 1e-10
30
31 #define ll long long
32
33 #define pa pair<int,int>
34
35 #define for0(i,n) for(int i=0;i<=(n);i++)
36
37 #define for1(i,n) for(int i=1;i<=(n);i++)
38
39 #define for2(i,x,y) for(int i=(x);i<=(y);i++)
40
41 using namespace std;
42
43 inline int read()
44
45 {
46
47 int x=0,f=1;char ch=getchar();
48
49 while(ch<‘0‘||ch>‘9‘){if(ch==‘-‘)f=-1;ch=getchar();}
50
51 while(ch>=‘0‘&&ch<=‘9‘){x=10*x+ch-‘0‘;ch=getchar();}
52
53 return x*f;
54
55 }
56 int n,m,ans,a[maxn][maxn],f[maxn][maxn];
57 inline int check(int x,int y)
58 {
59 //cout<<x<<‘ ‘<<y<<endl;
60 for1(i,n)
61 for1(j,m)
62 {
63 f[i][j]=f[i-1][j]+f[i][j-1]-f[i-1][j-1];
64 int tmp=f[i][j]-f[max(i-x,0)][j]-f[i][max(j-y,0)]+f[max(i-x,0)][max(j-y,0)];
65 tmp=a[i][j]-tmp;
66 if(tmp<0)return inf;
67 f[i][j]+=tmp;
68 //cout<<i<<‘ ‘<<j<<‘ ‘<<f[i][j]<<endl;
69 }
70 return f[n][m];
71 }
72
73 int main()
74
75 {
76
77 freopen("input.txt","r",stdin);
78
79 freopen("output.txt","w",stdout);
80
81 n=read();m=read();
82 ans=0;
83 for1(i,n)
84 for1(j,m)
85 a[i][j]=read(),ans+=a[i][j];
86 for1(i,n)
87 for1(j,m)
88 if(i!=1||j!=1)ans=min(ans,check(i,j));
89 printf("%d\n",ans);
90 return 0;
91
92 }