#include <bits/stdc++.h>
using namespace std;
int a[100000];
int startConsecutive(int m) {
  for (int i = 0; i < m; i++) {
    if (a[i] != i + 1) {
      return i;
    }
  }
  return m;
}
int main(int argc, char *argv[]) {
  int n, k;
  cin >> n >> k;
  int m;
  int answer = 0;
  int consecutive = 0;
  for (int i = 0; i < k; i++) {
    cin >> m;
    for (int j = 0; j < m; j++) {
      cin >> a[j];
    }
    int c = startConsecutive(m);
    answer += (m - 1);
    if (c) consecutive = c;
  }
  std::cout << answer - (consecutive - 1) + (n - 1) - (consecutive - 1)
            << std::endl;
  return 0;
}
