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