#include <bits/stdc++.h>
using namespace std;
int n, k, i, j, m[100005], a[100005], ans = 0;
int main() {
  scanf("%d%d", &n, &k);
  for (i = 1; i <= k; i++) {
    scanf("%d", &m[i]);
    for (j = 1; j <= m[i]; j++) scanf("%d", &a[j]);
    if (a[1] == 1) {
      for (j = 0; j < m[i] && a[j + 1] == j + 1; j++)
        ;
      ans += n - j;
      m[i] = m[i] - j + 1;
    }
    ans += m[i] - 1;
  }
  printf("%d", ans);
}
