#include <bits/stdc++.h>
using namespace std;
int n, m, i, j, k, l, T, c = 0;
int main() {
  cin >> n >> m;
  int jj = 1;
  for (i = 0; i < m; i++) {
    int u, w = 0, w1, t = 0, t1 = 0;
    scanf("%d", &u);
    scanf("%d", &w1);
    if (w1 != 1) {
      c += u - 1;
      t = 1;
    }
    for (j = 1; j < u; j++) {
      t1++;
      int v;
      scanf("%d", &v);
      if (v != j + 1 and t == 0) {
        c += u - t1;
        jj = j;
        t = 1;
      }
    }
    if (t == 0) jj = j;
  }
  c += n - jj;
  cout << c;
}
