#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  scanf("%d %d", &n, &k);
  int ans = 0, components = 0;
  while (k--) {
    int m, x, in;
    scanf("%d %d", &m, &x);
    if (x == 1) {
      int pos = -1;
      for (int i = 1; i < m; ++i) {
        scanf("%d", &in);
        if (pos != -1) continue;
        if (in - 1 != x) pos = i;
        x = in;
      }
      ++components;
      if (pos != -1) ans += (m - pos), components += (m - pos);
    } else {
      for (int i = 1; i < m; ++i) scanf("%d", &in);
      ans += m - 1;
      components += m;
    }
  }
  ans += components - 1;
  printf("%d\n", ans);
  return 0;
}
