#include <bits/stdc++.h>
using namespace std;
long long a[10][100000];
map<pair<long long, long long>, long long> tt;
pair<long long, long long> pa(long long i, long long j) {
  return make_pair(i, j);
}
long long che(long long k) { return k * (k - 1) / 2; }
int main() {
  ios_base::sync_with_stdio(false);
  long long n, m;
  cin >> n >> m;
  for (long long i = 0; i < m; i++) {
    for (long long j = 0; j < n; j++) {
      cin >> a[i][j];
    }
  }
  for (long long i = 0; i < m; i++) {
    for (long long j = 0; j < n - 1; j++) {
      tt[pa(a[i][j], a[i][j + 1])]++;
    }
  }
  long long ans = 0;
  for (long long i = 0; i < n - 1; i++) {
    if (tt[pa(a[0][i], a[0][i + 1])] == m) {
      long long j = i;
      while (j < n - 1 && tt[pa(a[0][j], a[0][j + 1])] == m) {
        j++;
      }
      ans += che(j - i + 1);
      i = j;
    }
  }
  cout << ans + n << endl;
}
