#include <bits/stdc++.h>
using namespace std;
int p[100010] = {0}, d[100010], n, k, a[100010], ans = 0, ac[100010], flag = 1;
void solve(int x) {
  if (x > n) return;
  if (p[x] == 0 || (p[x] == x + 1 && flag)) {
    if (p[x] == 0)
      flag = 0, ans += (x != n), solve(x + 1);
    else
      solve(x + 1);
    return;
  }
  flag = 0;
  ans += d[x];
  for (int j = p[x], t; j > 0;) {
    t = p[j];
    d[j] = 0;
    p[j] = 0;
    j = t;
  }
  ans++;
  solve(x + 1);
}
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 0, t; i < k; ++i) {
    scanf("%d", &t);
    for (int j = 1; j <= t; ++j) {
      scanf("%d", a + j);
      d[a[j]] = t - j;
    }
    for (int j = t; j > 1; --j) p[a[j - 1]] = a[j];
    for (int j = 1; j <= t; ++j) ac[a[j]] = a[t];
  }
  solve(1);
  printf("%d", ans);
  return 0;
}
