//qscqesze
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <bitset>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define maxn 200500
#define mod 1001
#define eps 1e-9
#define pi 3.1415926
int Num;
//const int inf=0x7fffffff;
const ll inf=999999999;
inline ll read()
{
ll x=0,f=1;char ch=getchar();
while(ch<‘0‘||ch>‘9‘){if(ch==‘-‘)f=-1;ch=getchar();}
while(ch>=‘0‘&&ch<=‘9‘){x=x*10+ch-‘0‘;ch=getchar();}
return x*f;
}
//*************************************************************************************
int M[110][110];
int sum = 0;
int ans = inf;
int T[110][110];
int n,m;
void work(int x,int y)
{
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
T[i][j]=M[i][j];
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
if(T[i][j])
{
int tmp = T[i][j];
if(i+x-1>n)return;
if(j+y-1>m)return;
for(int ii=0;ii<x;ii++)
{
for(int jj=0;jj<y;jj++)
{
T[i+ii][j+jj]-=tmp;
if(T[i+ii][j+jj]<0)return;
}
}
}
}
}
ans = sum/(x*y);
}
int main()
{
n=read(),m=read();
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
M[i][j]=read(),sum+=M[i][j];
for(int i=n;i>=1;i--)
{
for(int j=m;j>=1;j--)
{
if(sum%(i*j)==0&&ans>sum/(i*j))
{
work(i,j);
}
}
}
printf("%d\n",ans);
}