#include <bits/stdc++.h>
using namespace std;
long long int n, m, b[200005];
long long int a[12][200005];
long long int ans[200005];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> m;
  for (long long int i = 1; i <= m; i++) {
    for (long long int j = 1; j <= n; j++) {
      long long int d;
      cin >> d;
      b[j] = d;
      a[i][d] = j;
    }
  }
  ans[b[1]] = 1;
  for (long long int i = 2; i <= n; i++) {
    long long int first = 1;
    ans[b[i]] = 1;
    for (long long int j = 1; j <= m; j++) {
      if (a[j][b[i]] - a[j][b[i - 1]] != 1) first = 0;
    }
    if (first) ans[b[i]] += ans[b[i - 1]];
  }
  long long int ok = 0;
  for (long long int i = 1; i <= n; i++) ok += ans[b[i]];
  cout << ok;
  return 0;
}
