#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  while (cin >> n >> k) {
    vector<int> pieces(k);
    for (int i = 0; i < k; ++i) {
      int m;
      cin >> m;
      vector<int> doll(m);
      for (int j = 0; j < m; ++j) {
        cin >> doll[j];
      }
      if (doll[0] == 1) {
        int j = 0;
        while (j < m and doll[j] == j + 1) ++j;
        pieces[i] = m - j + 1;
      } else {
        pieces[i] = m;
      }
    }
    int res = 0;
    for (int i = 0; i < k; ++i) {
      res += pieces[i] * 2 - 1;
    }
    res -= 1;
    cout << res << endl;
  }
}
