#include<iostream> #include<cstring> #include<algorithm> #include<cmath> #include<cstdio> #include<queue> using namespace std; int ucol[1005],dcol[1005],lrow[1005],rrow[1005]; int numr[1005],numc[1005]; int a[1005][1005]; int main(){ int n,m; while(scanf("%d%d",&n,&m)!=EOF){ long long ans=0; memset(ucol,0,sizeof(ucol)); memset(dcol,0,sizeof(dcol)); memset(lrow,0,sizeof(lrow)); memset(rrow,0,sizeof(rrow)); memset(numr,0,sizeof(numr)); memset(numc,0,sizeof(numc)); for(int i=1;i<=n;i++){ for(int j=1;j<=m;j++){ scanf("%d",&a[i][j]); if(a[i][j]){ numr[i]++; numc[j]++; if(!lrow[i]) lrow[i]=j; rrow[i]=j; if(!ucol[j]) ucol[j]=i; dcol[j]=i; } } } for(int i=1;i<=n;i++){ if(lrow[i]&&lrow[i]==rrow[i]){ ans+=m-1; continue; } if(lrow[i]) ans+=m-lrow[i]-(numr[i]-1); if(rrow[i]) ans+=rrow[i]-1-(numr[i]-1); } for(int i=1;i<=m;i++){ if(dcol[i]&&dcol[i]==ucol[i]){ ans+=n-1; continue; } if(dcol[i]) ans+=dcol[i]-1-(numc[i]-1); if(ucol[i]) ans+=n-ucol[i]-(numc[i]-1); } printf("%d\n",ans); } }