#include <bits/stdc++.h>
using namespace std;
long long old, ne, res, rr, cur;
long long n, k, m[100005];
vector<long long> nhom[100005], d[100005];
int main() {
  cin >> n >> k;
  for (int i = 1; i <= k; i++) {
    cin >> m[i];
    cin >> old;
    d[cur].push_back(old);
    for (int j = 2; j <= m[i]; j++) {
      cin >> ne;
      if ((ne - 1) != old) {
        nhom[i].push_back(d[cur].size());
        ++cur;
      }
      d[cur].push_back(ne);
      old = ne;
    }
    nhom[i].push_back(d[cur].size());
    ++cur;
  }
  for (int i = 1; i <= k; i++) {
    res += (m[i] - nhom[i][0]);
    for (int j = 1; j < nhom[i].size(); j++) res += nhom[i][j] - 1;
  }
  sort(d, d + cur - 1);
  for (int i = 1; i < cur; i++) {
    res += d[i].size() - 1;
    ++res;
    res += d[i].size() - 1;
  }
  cout << res;
}
