#include <bits/stdc++.h>
using namespace std;
const int N = 1e5;
int a[10][N], idx[10][N];
int l[10], r[10];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, m;
  cin >> n >> m;
  for (int j = 0; j < m; j++) {
    for (int i = 0; i < n; i++) {
      cin >> a[j][i];
      a[j][i]--;
      idx[j][a[j][i]] = i;
    }
  }
  long long ans = 0;
  for (; r[0] < n; r[0]++) {
    const int x = a[0][r[0]];
    if (r[0] == 0) {
      for (int j = 0; j < m; j++) {
        l[j] = r[j] = idx[j][x];
      }
    } else {
      bool valid = true;
      for (int j = 1; j < m; j++) {
        if (idx[j][x] != r[j] + 1)
          valid = false;
        else
          r[j]++;
      }
      if (!valid) {
        for (int j = 0; j < m; j++) {
          l[j] = r[j] = idx[j][x];
        }
      }
    }
    ans += (r[0] - l[0] + 1);
  }
  cout << ans << endl;
  return 0;
}
