#include <bits/stdc++.h>
using namespace std;
int a[12][100005], dp[100005], last[100005];
int main(void) {
  long long ans;
  int n, m, i, j;
  scanf("%d%d", &n, &m);
  for (i = 1; i <= m; i++) {
    for (j = 1; j <= n; j++) {
      scanf("%d", &a[i][j]);
      if (i == 1)
        last[a[i][j]] = a[i][j - 1];
      else {
        if (last[a[i][j]] != a[i][j - 1]) last[a[i][j]] = 0;
      }
    }
  }
  ans = 0;
  for (i = 1; i <= n; i++) {
    if (last[a[1][i]] == 0)
      dp[a[1][i]] = 1;
    else
      dp[a[1][i]] = dp[last[a[1][i]]] + 1;
    ans += dp[a[1][i]];
  }
  printf("%lld\n", ans);
  return 0;
}
