#include <bits/stdc++.h>
using namespace std;
vector<int> tab[100009];
int main() {
  int n;
  int k;
  scanf("%d%d", &n, &k);
  int w = 0;
  int frag = k;
  for (int i = 0; i < k; ++i) {
    int m;
    scanf("%d", &m);
    for (int j = 0; j < m; ++j) {
      int a;
      scanf("%d", &a);
      tab[i].push_back(a);
    }
    for (int j = 1; j < m; ++j) {
      if (tab[i][j] != j + 1) {
        w += m - j;
        frag += m - j;
        break;
      }
    }
  }
  printf("%d\n", w + frag - 1);
  return 0;
}
