#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, t;
  int k, ma = 1, ss = 0, l = 1;
  cin >> n >> k;
  int s[k];
  vector<int> arr[k + 1];
  for (int i = 0; i < k; i++) {
    cin >> s[i];
    for (int j = 0; j < s[i]; j++) {
      cin >> t;
      arr[i].push_back(t);
      if ((arr[i][j - 1] + 1 == arr[i][j]) && j > 0 && arr[i][0] == 1)
        l++;
      else
        l = 1;
      if (ma < l) {
        ss = i;
        ma = l;
      }
    }
  }
  int an = 0;
  for (int i = 0; i < k; i++) {
    if (i == ss) {
      an += 2 * (s[i] - ma);
    } else
      an += (s[i] - 1) + s[i];
  }
  cout << an;
  return 0;
}
