#include <bits/stdc++.h>
int a[2000][2000] = {0};
int b[2000][2000] = {0};
int c[2000][2000] = {0};
int ss[2000][2000] = {0};
int st[2000][2000] = {0};
int main() {
  int n, m, i, j;
  scanf("%d %d", &n, &m);
  int ans = 0;
  for (i = 0; i < n; i++) {
    int g = 0;
    for (j = 0; j < m; j++) {
      scanf("%d", &a[i][j]);
      if (a[i][j] == 0) {
        if (j > 0) {
          b[i][j] = b[i][j - 1] + 1;
        } else
          b[i][j]++;
        if (i > 0) {
          c[i][j] = c[i - 1][j] + 1;
        } else {
          c[i][j]++;
        }
      } else {
        if (j > 0) {
          b[i][j] = b[i][j - 1];
        }
        ans += b[i][j];
        b[i][j] = 0;
        if (i > 0) {
          c[i][j] = c[i - 1][j];
        }
        ans += c[i][j];
        c[i][j] = 0;
      }
    }
  }
  for (i = n - 1; i >= 0; i--) {
    for (j = m - 1; j >= 0; j--) {
      if (a[i][j] == 0) {
        if (j < m - 1) {
          ss[i][j] = ss[i][j + 1] + 1;
        } else
          ss[i][j]++;
        if (i < n - 1) {
          st[i][j] = st[i + 1][j] + 1;
        } else {
          st[i][j]++;
        }
      } else {
        if (j < m - 1) {
          ss[i][j] = ss[i][j + 1];
        }
        ans += ss[i][j];
        ss[i][j] = 0;
        if (i < n - 1) {
          st[i][j] = st[i + 1][j];
        }
        ans += st[i][j];
        st[i][j] = 0;
      }
    }
  }
  printf("%d\n", ans);
}
