#include <bits/stdc++.h>
using namespace std;
template <class T>
void amax(T &x, T y) {
  if (x < y) x = y;
}
template <class T>
void amin(T &x, T y) {
  if (x > y) x = y;
}
int n, m;
const int SIZE = 1e5 + 10;
int arr[SIZE], nxt[SIZE];
bool pre[SIZE];
long long ans = 0, cur_size, id;
void solve() {
  cin >> n >> m;
  while (--m >= 0) {
    for (__typeof(1) i = (1); i <= (n); ++i) cin >> arr[i];
    for (__typeof(1) i = (1); i <= (n - 1); ++i) {
      if (nxt[arr[i]] == 0)
        nxt[arr[i]] = arr[i + 1];
      else if (nxt[arr[i]] == -1)
        continue;
      else if (nxt[arr[i]] != arr[i + 1])
        nxt[arr[i]] = -1;
    }
    nxt[arr[n]] = -1;
  }
  for (__typeof(1) i = (1); i <= (n); ++i) {
    if (nxt[i] != -1) pre[nxt[i]] = true;
  }
  for (__typeof(1) i = (1); i <= (n); ++i) {
    if (!pre[i]) {
      cur_size = 0, id = i;
      while (id != -1) ++cur_size, id = nxt[id];
      ans += cur_size * (cur_size + 1) / 2;
    }
  }
  cout << ans << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  solve();
  return 0;
}
