#include <bits/stdc++.h>
using namespace std;
long long md(long long a) {
  return ((a % 1000000007) + 1000000007) % 1000000007;
}
long long p(long long a, long long b) {
  if (b == 0) return 1ll;
  long long x = p(a, b >> 1);
  if (b & 1) return md(x * md(a * x));
  return md(x * x);
}
int main() {
  int n, k;
  scanf("%d %d", &n, &k);
  vector<vector<int>> mat(k);
  int ind1 = -1;
  for (int i = 0; i < k; i++) {
    int m;
    scanf("%d", &m);
    mat[i].resize(m);
    for (int &j : mat[i]) {
      scanf("%d", &j);
      if (j == 1) ind1 = i;
    }
  }
  if (k == 1) {
    printf("0\n");
    return 0;
  }
  int l = 1;
  int tba = 0;
  for (int i = 0; i < (int)mat[ind1].size(); i++) {
    if (mat[ind1][i] != l) {
      tba = (int)mat[ind1].size() - i;
      break;
    }
    l++;
  }
  int ans = n - l + 1;
  for (int i = 0; i < k; i++) {
    if (i == ind1) {
      ans += tba;
    } else {
      ans += (int)mat[i].size() - 1;
    }
  }
  printf("%d\n", ans);
}
