#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, num, k, i, status = 0, res = 0, cur, count;
  cin >> n >> k;
  for (i = 0; i < k; i++) {
    count = 1;
    cin >> num;
    cin >> cur;
    if (cur == 1) status = 1;
    for (int j = 2; j <= num; j++) {
      cin >> cur;
      if (1 == status) {
        if (j == cur)
          count++;
        else
          status = 0;
      }
    }
    res += (num - count);
  }
  cout << 2 * res + k - 1 << endl;
  return 0;
}
