#include <bits/stdc++.h>
using namespace std;
int ne, res, rr, cur;
int n, k, m;
int main() {
  cin >> n >> k;
  for (int i = 1; i <= k; i++) {
    cin >> m;
    int mm = m;
    for (int j = 1; j <= m; j++) {
      cin >> ne;
      if (ne - 1 == cur)
        ++cur;
      else if (cur != 0) {
        res = res - cur + 1;
        mm = mm - cur + 1;
        cur = 0;
      }
    }
    if (cur != 0) {
      res = res - cur + 1;
      mm = mm - cur + 1;
      cur = 0;
    }
    res += mm - 1;
  }
  cout << res + n - 1;
}
