#include <bits/stdc++.h>
using namespace std;
const int64_t N = 1e5 + 9;
const int64_t M = 1e9 + 7;
int64_t n, m, dp[N], a[20][N];
map<int64_t, set<int64_t> > s;
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m;
  for (int64_t i = 1; i <= m; i++)
    for (int64_t j = 1; j <= n; j++) cin >> a[i][j];
  for (int64_t i = 1; i <= m; i++)
    for (int64_t j = n; j; j--)
      if (j != n)
        s[a[i][j]].insert(a[i][j + 1]);
      else
        s[a[i][j]].insert(-1);
  for (int64_t i = n; i; i--) {
    dp[i] = 1;
    if (s[a[1][i]].size() != 1) continue;
    dp[i] += dp[i + 1];
  }
  for (int64_t i = 2; i <= n; i++) dp[i] += dp[i - 1];
  cout << dp[n] << endl;
}
