#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, K;
  cin >> N >> K;
  vector<vector<int> > V(K);
  int TOT = 0, ALL = 0;
  for (int i = 0; i < K; ++i) {
    int m;
    cin >> m;
    V[i] = vector<int>(m);
    int f = 1, cn = 0;
    for (int j = 0; j < m; ++j) {
      cin >> V[i][j];
      if (V[i][j] == f) cn++;
      f++;
    }
    int MN = m - max(0, (cn - 1));
    TOT += max(0, MN - 1);
    ALL += MN;
  }
  cout << TOT + (ALL - 1) << endl;
}
