#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 7;
const int M = 1e6 + 7;
const int lim = 1e8;
const int inf = 0x3f3f3f3f;
int a[N];
int main() {
  int n, k, sum = 0, num = 0;
  scanf("%d%d", &n, &k);
  while (k--) {
    int m;
    scanf("%d%d", &m, &a[0]);
    if (a[0] == 1) {
      int pos = m;
      for (int i = 1; i < m; i++) {
        scanf("%d", &a[i]);
        if (a[i] != i + 1) {
          sum += 2;
          pos = i;
          break;
        }
      }
      for (int i = pos + 1; i < m; i++) {
        scanf("%d", &a[i]);
        sum += 2;
      }
    } else {
      for (int i = 1; i < m; i++) scanf("%d", &a[i]);
      sum += 2 * m - 1;
    }
  }
  printf("%d\n", sum);
  return 0;
}
