#include <bits/stdc++.h>
using namespace std;
const int N = 100001;
int n, k, m, arr[N];
int parent[N];
int ans;
void split(int u) {
  if (parent[u] == u) return;
  split(parent[u]);
  parent[u] = u;
  ++ans;
}
int main() {
  scanf("%d %d", &n, &k);
  for (int i = 0; i < n; ++i) parent[i] = i;
  for (int i = 0; i < k; ++i) {
    scanf("%d", &m);
    for (int j = 0; j < m; ++j) {
      scanf("%d", &arr[j]);
      arr[j] -= 1;
    }
    for (int j = 0; j < m - 1; ++j) parent[arr[j]] = arr[j + 1];
  }
  for (int i = 0; i < n - 1; ++i) {
    if (parent[i] == i) {
      if (parent[i + 1] == i + 1) {
        parent[i] = i + 1;
        ++ans;
      } else {
        split(i + 1);
        parent[i] = i + 1;
        ++ans;
      }
    } else if (parent[i] != i + 1) {
      split(i);
      if (parent[i + 1] == i + 1) {
        parent[i] = i + 1;
        ++ans;
      } else {
        split(i + 1);
        parent[i] = i + 1;
        ++ans;
      }
    }
  }
  printf("%d\n", ans);
  return 0;
}
