#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<vector<int> > a(10, vector<int>(100000));
vector<vector<int> > numToPos(10, vector<int>(1000001));
long long int bestLength(int l) {
  long long int ans = n - l;
  for (int i = 1; i < m; ++i) {
    int l1 = numToPos[i][a[0][l]];
    long long int curLen = 0;
    while (l1 + curLen < n && l + curLen < n &&
           a[0][l + curLen] == a[i][l1 + curLen]) {
      ++curLen;
    }
    ans = min(ans, curLen);
  }
  return ans;
}
long long int calculateAnswer() {
  long long int ans = 0;
  for (long long int i = 0; i < n; ++i) {
    long long int bl = bestLength(i);
    ans += bl * (bl + 1) / 2;
    i += bl - 1;
  }
  return ans;
}
int main(int argc, char** argv) {
  ios::sync_with_stdio(0);
  cin >> n >> m;
  for (int i = 0; i < m; ++i) {
    for (int j = 0; j < n; ++j) {
      cin >> a[i][j];
      numToPos[i][a[i][j]] = j;
    }
  }
  cout << calculateAnswer() << "\n";
  return 0;
}
