#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  int arr[m][n];
  int mp[m + 1][n + 1];
  for (int i = 0; i < m; ++i) {
    for (int j = 0; j < n; ++j) {
      scanf("%d", &arr[i][j]);
      mp[i][arr[i][j]] = j;
    }
  }
  int arr1[m];
  long long int ans = 0;
  if (m == 1) {
    long long int kl = n;
    cout << (kl * (kl + 1)) / 2;
    return 0;
  }
  for (int i = 0; i < n;) {
    int cur = i;
    for (int j = 1; j < m; ++j) {
      arr1[j] = mp[j][arr[0][cur]];
    }
    while (1) {
      bool fg = 0;
      for (int j = 1; j < m; ++j) {
        if (arr1[j] >= n) {
          fg = 1;
          break;
        }
        if (arr[j][arr1[j]] == arr[0][cur]) {
          arr1[j]++;
        } else {
          fg = 1;
          break;
        }
      }
      if (fg == 0) {
        ans = ans + cur - i + 1;
        cur++;
      } else {
        i = cur;
        break;
      }
    }
  }
  cout << ans;
  return 0;
}
