#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k, t, p;
  scanf("%d %d", &n, &k);
  int c = 0;
  int total = 0;
  int val = 0;
  for (int i = 1; i <= k; i++) {
    scanf("%d", &t);
    int flag = 0;
    scanf("%d", &p);
    if (p == 1) flag = 1;
    for (int j = 1; j < t; j++) {
      scanf("%d", &p);
      if (flag == 1 && p == j + 1) {
        c++;
      } else
        flag = 0;
    }
    if (c > 0) {
      val = c;
    }
    total = total + t - c - 1;
    c = 0;
  }
  cout << total + n - val - 1 << endl;
  return 0;
}
