#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 7;
int n, m;
int a[12][N];
void input() {
  scanf("%d %d", &n, &m);
  for (int i = (1); i <= (m); i++)
    for (int j = (1); j <= (n); j++) {
      scanf("%d", &a[i][j]);
    }
}
int reach[N];
void output() {
  long long res = 0;
  for (int j = (1); j <= (n); j++) {
    res += reach[j] - j + 1;
  }
  printf("%lld\n", res);
}
void init() {
  int mapping[n + 1];
  for (int j = (1); j <= (n); j++) {
    mapping[a[1][j]] = j;
  }
  for (int i = (1); i <= (m); i++)
    for (int j = (1); j <= (n); j++) {
      a[i][j] = mapping[a[i][j]];
    }
  for (int j = (1); j <= (n); j++) {
    reach[j] = n;
  }
}
void solve() {
  init();
  for (int i = (1); i <= (m); i++) {
    int prev = 1;
    for (int j = (1); j <= (n); j++) {
      if (a[i][j] + 1 != a[i][j + 1]) {
        int end = a[i][j];
        for (int k = (prev); k <= (j); k++) {
          reach[a[i][k]] = min(reach[a[i][k]], end);
        }
        prev = j + 1;
      }
    }
  }
}
int main() {
  {
    input();
    solve();
    output();
  }
  return 0;
}
