#include <bits/stdc++.h>
inline long long Input() {
  long long ret = 0;
  bool isN = 0;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') isN = 1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    ret = ret * 10 + c - '0';
    c = getchar();
  }
  return isN ? -ret : ret;
}
inline void Output(long long x) {
  if (x < 0) {
    putchar('-');
    x = -x;
  }
  int len = 0, data[20];
  while (x) {
    data[len++] = x % 10;
    x /= 10;
  }
  if (!len) data[len++] = 0;
  while (len--) putchar(data[len] + 48);
  putchar('\n');
}
#pragma comment(linker, "/STACK:124000000,124000000")
const long double PI = acos(-1.0);
using namespace std;
int n, k, x, y;
int q[100005];
int head, tail;
vector<int> g;
int main() {
  int ans = 0;
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= k; i++) {
    head = tail = 0;
    scanf("%d", &x);
    for (int i = 0; i < x; i++) {
      scanf("%d", &y);
      q[tail++] = y;
    }
    if (q[0] != 1)
      ans += (2 * x - 1);
    else {
      for (int i = 0; i < tail; i++) {
        if (q[i] != i + 1) {
          ans += (tail - i) * 2;
          break;
        }
      }
    }
  }
  printf("%d\n", ans);
  return 0;
}
