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