#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int arr[11][N];
int pos[11][N];
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int j = 0; j < m; j++) {
    for (int i = 0; i < n; i++) {
      scanf("%d", &arr[j][i]);
      pos[j][arr[j][i]] = i;
    }
  }
  long long ans = 0;
  int cnt = 1;
  for (int i = 1; i < n; i++) {
    bool ok = true;
    int fir = arr[0][i - 1];
    int sec = arr[0][i];
    for (int j = 1; j < m; j++) {
      if (pos[j][fir] + 1 != pos[j][sec]) {
        ok = false;
        break;
      }
    }
    if (ok)
      cnt++;
    else {
      ans += 1LL * cnt * (cnt + 1) / 2;
      cnt = 1;
    }
  }
  ans += 1LL * cnt * (cnt + 1) / 2;
  printf("%I64d\n", ans);
}
