#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e9 + 7;
const double PI = acos(-1.0);
void solve() {
  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> act;
  for (int a = 1; a <= n; a++)
    for (int b = 1; b <= m; b++) {
      int in;
      cin >> in;
      if (in) act.push_back(make_pair(a, b));
    }
  int pat = act[0].first, res = 0, act_sz = (int)act.size();
  for (int a = 0; a < act_sz; a++) {
    if (a == 0)
      res += act[a].second - 1;
    else if (act[a].first != pat) {
      res += m - act[a - 1].second;
      res += act[a].second - 1;
      pat = act[a].first;
    } else if (act[a].first == pat)
      res += (act[a].second - act[a - 1].second - 1) * 2;
    if (a == act_sz - 1) res += m - act[a].second;
    if (a >= 2) swap(act[a - 2].first, act[a - 2].second);
  }
  if (act_sz >= 2) swap(act[act_sz - 2].first, act[act_sz - 2].second);
  swap(act[act_sz - 1].first, act[act_sz - 1].second);
  sort(act.begin(), act.end());
  pat = act[0].first;
  for (int a = 0; a < act_sz; a++) {
    if (a == 0)
      res += act[a].second - 1;
    else if (act[a].first != pat) {
      res += n - act[a - 1].second;
      res += act[a].second - 1;
      pat = act[a].first;
    } else if (act[a].first == pat)
      res += (act[a].second - act[a - 1].second - 1) * 2;
    if (a == act_sz - 1) res += n - act[a].second;
  }
  cout << res;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  solve();
  cerr << endl << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << "s.\n";
  return 0;
}
