#include <bits/stdc++.h>
using namespace std;
int n, m;
int D[11][100001], mt[11][100001], F[11][100001];
long long f[100001];
void solve() {
  cin >> n >> m;
  for (int i = 1; i <= m; i++)
    for (int j = 1; j <= n; j++)
      cin >> mt[i][j], D[i][mt[i][j]] = j, F[i][j] = 1;
  mt[1][0] = '$';
  if (m == 1) {
    cout << (long long)n * (n + 1) / 2;
    return;
  }
  f[0] = 0;
  for (int i = 1; i <= n; i++) {
    int tm = INT_MAX;
    f[i] = f[i - 1];
    for (int j = 2; j <= m; j++) {
      int r = D[j][mt[1][i]];
      if (mt[j][r - 1] == mt[1][i - 1]) F[j][r] += F[j][r - 1];
      tm = min(tm, F[j][r]);
    }
    f[i] += (long long)tm;
  }
  cout << f[n];
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  solve();
}
