#include <bits/stdc++.h>
using namespace std;
vector<vector<long long int> > a;
long long int m[500005];
int main() {
  long long int n, k;
  int xin, yin;
  long long int i, j, f, temp;
  cin >> n >> k;
  a = vector<vector<long long int> >(n + 2);
  long long int fans = 0;
  for (i = 1; i <= k; i++) {
    cin >> m[i];
    fans += m[i] - 1;
    for (j = 1; j <= m[i]; j++) {
      cin >> temp;
      a[i].push_back(temp);
      if (temp == 1) {
        xin = i;
        yin = j - 1;
      }
    }
  }
  long long int ct;
  fans = 0;
  ct = 1;
  f = 0;
  while (ct <= n) {
    if (m[xin] <= yin) {
      f = 2;
      break;
    }
    if (a[xin][yin] != ct) {
      f = 1;
      break;
    }
    ct++;
    yin++;
  }
  for (i = 1; i <= k; i++) {
    if (i != xin) {
      fans += m[i] - 1;
    }
  }
  fans += (n - ct + 1);
  fans += (m[xin] - yin);
  cout << fans << "\n";
  return 0;
}
