#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.sync_with_stdio(0);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  int re = 0;
  vector<int> a[101010];
  int ss = 0;
  for (int i = 0; i < k; i++) {
    int m;
    cin >> m;
    a[i] = vector<int>(m);
    for (int j = 0; j < m; j++) cin >> a[i][j];
    if (a[i][0] != 1) {
      ss += m;
      re += m - 1;
      continue;
    }
    int lis = m;
    for (int j = 1; j < m; j++) {
      if (a[i][j] != j + 1) {
        break;
      } else {
        lis--;
      }
    }
    ss += lis;
    re += lis - 1;
  }
  cout << re + ss - 1 << endl;
  return 0;
}
