#include <bits/stdc++.h>
const int MAXN = 100000 + 5;
using std::vector;
vector<int> G[MAXN];
vector<bool> op[MAXN];
std::pair<int, int> pos[MAXN];
int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  for (int i = 0; i < k; ++i) {
    int t;
    scanf("%d", &t);
    for (int j = 0; j < t; ++j) {
      int tt;
      scanf("%d", &tt);
      pos[tt] = std::pair<int, int>(i, j);
      G[i].push_back(tt);
      op[i].push_back(0);
    }
    op[i][t - 1] = 1;
  }
  int ans = 0;
  int now = 0;
  for (int i = 0; i < k; ++i)
    if (G[i][0] == 1) {
      int j;
      for (j = 0; j < G[i].size(); ++j)
        if (G[i][j] != j + 1) break;
      now = j + 1;
      for (; j < G[i].size(); ++j) ++ans, op[i][j] = 1;
      break;
    }
  for (int i = now; i <= n; ++i) {
    int p1 = pos[i].first, p2 = pos[i].second;
    if (!op[p1][p2]) {
      for (int j = p2; j < op[p1].size() && !op[p1][j]; ++j) {
        op[p1][j] = 1;
        ++ans;
      }
    }
    ++ans;
  }
  printf("%d\n", ans);
}
