#include <bits/stdc++.h>
using namespace std;
int v[11][100010];
int vmap[11][100010];
int pointer[11];
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  long long ans = 0;
  for (int j = 0; j < m; j++) {
    for (int i = 0; i < n; i++) {
      scanf("%d", &v[j][i]);
      v[j][i]--;
      vmap[j][v[j][i]] = i;
    }
  }
  bool isNew = true;
  long long sz;
  for (int i = 0; i < n; i++) {
    if (isNew) {
      for (int j = 1; j < m; j++) pointer[j] = vmap[j][v[0][i]];
      sz = 1;
      ans += 1;
      isNew = false;
    } else {
      bool check = true;
      sz++;
      for (int j = 1; j < m && check; j++) {
        pointer[j]++;
        if (pointer[j] >= n || v[j][pointer[j]] != v[0][i]) check = false;
      }
      if (check)
        ans += sz;
      else {
        isNew = true;
        i--;
      }
    }
  }
  cout << ans << endl;
  return 0;
}
