#include <bits/stdc++.h>
int main() {
  long long n, k;
  std::cin >> n >> k;
  std::vector<std::vector<long long>> chains(k);
  long long total = 0;
  long long rem = 0;
  for (long long i = 0; i < k; ++i) {
    long long num;
    std::cin >> num;
    chains[i].assign(num, 0);
    for (long long j = 0; j < num; ++j) {
      std::cin >> chains[i][j];
    }
    if (chains[i].front() == 1) {
      long long last = 1;
      for (last = 1; last < chains[i].size(); ++last) {
        if (chains[i][last] != last + 1) {
          break;
        }
      }
      last--;
      rem = last;
      total += num - last - 1;
    } else {
      total += num - 1;
    }
  }
  total += n - rem - 1;
  std::cout << total << std::endl;
  return 0;
}
