#include <bits/stdc++.h>
using namespace std;
int n, m, arr[20][100010], pos[20][100010], id[20];
bool check(int x) {
  for (int i = 2; i <= m; ++i) {
    ++id[i];
    if (arr[i][id[i]] != x) return false;
  }
  return true;
}
int main() {
  while (scanf("%d%d", &n, &m) != EOF) {
    for (int i = 1; i <= m; ++i) {
      for (int j = 1; j <= n; ++j) {
        scanf("%d", &arr[i][j]);
        pos[i][arr[i][j]] = j;
      }
    }
    long long res = 0, len = 1;
    for (int i = 2; i <= m; ++i) id[i] = pos[i][arr[1][1]];
    for (int i = 2; i <= n; ++i) {
      if (check(arr[1][i]) == false) {
        res += len * (len + 1) / 2;
        len = 1;
        for (int j = 2; j <= m; ++j) id[j] = pos[j][arr[1][i]];
      } else
        ++len;
    }
    res += len * (len + 1) / 2;
    printf("%lld\n", res);
  }
  return 0;
}
