#include <bits/stdc++.h>   using namespace std;   int n, m, ar[11][100005];   int rev[11][100005];   long long mx(int start) {     int val = ar[0][start];     for (int tmp = 0; tmp < n; ++tmp) {       for (int row = 1; row < m; ++row) {         int col = rev[row][val];         if (col + tmp >= n) {           return tmp;         }         int curVal = ar[row][col + tmp];         int val2 = ar[0][start + tmp];         if (curVal != val2) {           return tmp;         }       }     }     return n;   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 0; i < m; ++i) {       for (int j = 0; j < n; ++j) {         scanf( %d , ar[i] + j);         rev[i][ar[i][j]] = j;       }     }     long long ans = 0;     for (int i = 0; i < n;) {       long long mxi = mx(i);       ans += (mxi * (mxi + 1) / 2ll);       i += mxi;     }     cout << ans;     return 0;   }   