#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
const int M = 11;
int a[M][N];
int degIn[N];
map<int, int> to[N];
vector<int> b[N];
long long dp[N];
int n, m;
int main() {
  ios::sync_with_stdio(false);
  cin >> n >> m;
  for (int i = 1; i <= m; ++i) {
    for (int j = 1; j <= n; ++j) cin >> a[i][j];
  }
  for (int i = 1; i <= m; ++i) {
    for (int j = 1; j < n; ++j) {
      to[a[i][j]][a[i][j + 1]]++;
    }
  }
  for (int i = 1; i <= n; ++i) {
    for (auto it : to[i]) {
      if (it.second == m) {
        b[i].push_back(it.first);
        degIn[it.first]++;
      }
    }
  }
  queue<int> Q;
  for (int i = 1; i <= n; ++i) {
    if (degIn[i] == 0) {
      Q.push(i);
    }
  }
  for (int i = 1; i <= n; ++i) {
    dp[i] = 1;
  }
  while (!Q.empty()) {
    int u = Q.front();
    Q.pop();
    for (int v : b[u]) {
      degIn[v]--;
      if (degIn[v] == 0) {
        Q.push(v);
      }
      dp[v] += dp[u];
    }
  }
  long long ans = 0;
  for (int i = 1; i <= n; ++i) {
    ans += dp[i];
  }
  cout << ans << endl;
  return 0;
}
