#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, r;
  cin >> n >> m;
  r = n - 1;
  for (int i = 0, a; i < m; i++) {
    cin >> a;
    bool nd = true;
    int eq = 0;
    for (int j = 1, k; j <= a; j++) {
      cin >> k;
      if (k == j && nd) {
        eq++;
      } else
        nd = false;
    }
    if (eq) {
      r -= eq - 1;
      r += a - eq;
    } else
      r += a - 1;
  }
  cout << r;
}
