#include <bits/stdc++.h>
using namespace std;
vector<long long> a(100500);
int main() {
  long long n, m, k, i, j, q;
  cin >> n >> k;
  long long h = k, t = 0;
  for (j = 1; j <= k; j++) {
    cin >> a[0];
    for (i = 1; i <= a[0]; i++) {
      cin >> a[i];
    }
    if (a[1] == 1)
      for (i = 2; i <= a[0]; i++)
        if (a[i] - a[i - 1] > 1) {
          h += (a[0] - i + 1);
          t += (a[0] - i + 1);
          break;
        }
    if (a[1] > 1) {
      h += (a[0] - 1);
      t += (a[0] - 1);
    }
  }
  cout << h + t - 1;
  return 0;
}
