#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse4")
using namespace std;
int pos[12][(int)1e5 + 3];
int mat[12][(int)1e5 + 3];
int comLen(int r1, int r2, int c1, int mx) {
  int st = mat[r1][c1];
  int c2 = pos[r2][st];
  c2++;
  c1++;
  int ans = 1;
  while (mat[r1][c1] && mat[r2][c2] && ans < mx && mat[r2][c2] == mat[r1][c1]) {
    c1++;
    c2++;
    ans++;
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; ++i) {
    for (int j = 1; j <= n; ++j) {
      scanf("%d", &mat[i][j]);
      pos[i][mat[i][j]] = j;
    }
  }
  long long ans = 0;
  int tempLen = 1;
  for (int ind = 1; ind <= n;) {
    tempLen = n - ind + 1;
    for (int otr = 2; otr <= m; ++otr) {
      tempLen = comLen(1, otr, ind, tempLen);
    }
    ans += (tempLen * ((long long)tempLen + 1)) / 2;
    ind += tempLen;
  }
  printf("%lld", ans);
  return 0;
}
