#include <bits/stdc++.h>
using namespace std;
int n, m, fixRange;
vector<int> v[100100];
void init(void) {
  scanf("%d%d", &n, &m);
  for (int i = (1), _b = (m); i <= _b; i = i + 1) {
    int t;
    scanf("%d", &t);
    for (int love = 0, _n = (t); love < _n; love = love + 1) {
      int x;
      scanf("%d", &x);
      v[i].push_back(x);
    }
  }
}
void process(void) {
  int res = 0;
  for (int i = (1), _b = (m); i <= _b; i = i + 1)
    if (v[i][0] == 1) {
      int j = 0;
      while (j < v[i].size() && v[i][j] == j + 1) j++;
      fixRange = j;
    }
  for (int i = (1), _b = (m); i <= _b; i = i + 1)
    for (int j = 0, _n = (v[i].size()); j < _n; j = j + 1) {
      if (j > 0 && v[i][j] > fixRange) res++;
      if (v[i][j] > fixRange) res++;
    }
  printf("%d\n", res);
}
int main(void) {
  init();
  process();
  return 0;
}
