#include <bits/stdc++.h>
using namespace std;
vector<int> a[100114];
int f[100114];
int find_set(int x) { return f[x] == x ? f[x] : f[x] = find_set(f[x]); }
int main() {
  int n, k, m;
  scanf("%d%d", &n, &k);
  for (int i = 0; i <= n; i++) {
    f[i] = i;
  }
  int x, y;
  for (int i = 0; i < k; i++) {
    scanf("%d", &m);
    for (int j = 0; j < m; j++) {
      scanf("%d", &x);
      a[i].push_back(x);
    }
  }
  int cnt = 0;
  for (int i = 0; i < k; i++) {
    for (int j = 1; j < a[i].size(); j++) {
      if (a[i][j] != a[i][j - 1] + 1)
        cnt++;
      else {
        x = find_set(a[i][j]);
        y = find_set(a[i][j - 1]);
        f[x] = y;
      }
    }
  }
  int ans = 0;
  for (int i = 2; i <= n; i++) {
    if (f[i - 1] != f[i]) {
      ans++;
    }
  }
  printf("%d\n", ans + cnt);
  return 0;
}
