#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
const int inf = 1e9;
priority_queue<pair<int, int> > q;
vector<int> s[N];
int main() {
  int n, k, x;
  cin >> n >> k;
  for (int i = 0; i < k; ++i) {
    int tam;
    scanf("%d", &tam);
    for (int rep = 0; rep < tam; rep++) {
      scanf("%d", &x);
      s[i].push_back(x);
    }
    q.push({s[i].back(), i});
  }
  int answer = 0;
  int comp = 0;
  while (!q.empty()) {
    auto where = q.top();
    q.pop();
    int elem = where.first;
    int id = where.second;
    int tam = s[id].size();
    if (tam == 1 || q.size() == 0) {
      comp++;
    } else {
      answer++;
      comp++;
      s[id].pop_back();
      q.push({s[id].back(), id});
    }
  }
  cout << answer + comp - 1 << endl;
  return 0;
}
