#include <bits/stdc++.h>
using namespace std;
int main(int argc, char **argv) {
  int n, k;
  scanf("%d%d", &n, &k);
  int ans = 0;
  for (int i = 0; i < k; i++) {
    int mi;
    scanf("%d", &mi);
    int splits = 0;
    int x;
    scanf("%d", &x);
    if (x == 1) {
      for (int j = 2; j <= mi; j++) {
        scanf("%d", &x);
        if ((x != j) && (splits == 0)) {
          splits = (mi - j + 1);
        }
      }
    } else {
      for (int j = 2; j <= mi; j++) {
        scanf("%d", &x);
      }
      splits = mi - 1;
    }
    ans += splits;
  }
  ans += ans + k - 1;
  printf("%d\n", ans);
  return 0;
}
