#include <bits/stdc++.h>
using namespace std;
const int M = 1e5 + 5;
int fa[M], son[M], num[M];
int n, k, ans = 0;
void get(int x) {
  if (fa[x] == x) {
    fa[son[x]] = son[x];
    return;
  }
  ++ans;
  if (fa[fa[x]] != fa[x]) get(fa[x]);
  fa[x] = x;
}
int findfa(int x) {
  if (fa[x] == x) return x;
  return findfa(fa[x]);
}
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= k; ++i) {
    int m;
    scanf("%d", &m);
    for (int i = 1; i <= m; ++i) scanf("%d", num + i);
    for (int i = 2; i <= m; ++i) {
      fa[num[i - 1]] = num[i];
      son[num[i]] = num[i - 1];
    }
    fa[num[m]] = num[m];
    son[num[1]] = son[num[1]];
  }
  if (fa[n] != n) get(n);
  for (int i = n - 1; i >= 1; --i) {
    if (fa[i] == i + 1 || fa[i] == i)
      continue;
    else
      get(i);
  }
  for (int i = findfa(1); i <= n; ++i) {
    if (fa[i] != i) {
      get(i);
      ++ans;
    } else
      ++ans;
  }
  printf("%d\n", ans - 1);
  return 0;
}
