#include <bits/stdc++.h>
using namespace std;
vector<int> a[100010];
int m[100010], par[100010];
int bekan(int i) {
  if (par[i] == 0)
    return 0;
  else {
    int outp = bekan(par[i]) + 1;
    par[i] = 0;
    return outp;
  }
}
int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  for (int i = 0; i < k; i++) {
    scanf("%d", &m[i]);
    int ind = 0, x;
    for (int j = 0; j < m[i]; j++) {
      scanf("%d", &x), a[i].push_back(x);
      if (j) par[a[i][j - 1]] = a[i][j];
    }
  }
  int ans = 0;
  for (int i = 1; i < n; i++) {
    if (par[i] == i + 1) continue;
    ans += bekan(i + 1) + bekan(i);
    if (i) ans++;
  }
  cout << ans << endl;
}
