#include <bits/stdc++.h>
using namespace std;
int n, m;
int atas0[1010], kiri0;
bool atas1[1010], kiri1;
long long ans;
int main() {
  int i, j, x;
  scanf("%d%d", &n, &m);
  for (i = 0; i < n; i++) {
    kiri0 = 0;
    kiri1 = 0;
    for (j = 0; j < m; j++) {
      scanf("%d", &x);
      if (x) {
        ans += kiri0;
        kiri0 = 0;
        ans += atas0[j];
        atas0[j] = 0;
        atas1[j] = true;
        kiri1 = true;
      } else {
        if (kiri1) ans++;
        if (atas1[j]) ans++;
        atas0[j]++;
        kiri0++;
      }
    }
  }
  printf("%d\n", ans);
}
