#include <bits/stdc++.h>
using namespace std;
int b[100005] = {0}, e[100005] = {0};
pair<int, int> c[100005];
int d[100005] = {0};
int sz[100005];
int main() {
  int n, k;
  scanf("%d %d", &n, &k);
  for (int i = 1; i <= k; ++i) {
    scanf("%d", &sz[i]);
    vector<int> x(sz[i] + 1);
    for (int j = 1; j <= sz[i]; ++j) {
      scanf("%d", &x[j]);
      c[x[j]] = {i, j};
      if (j > 1) {
        b[x[j - 1]] = x[j];
        e[x[j]] = x[j - 1];
      }
    }
  }
  for (int i = 1; i <= n; ++i) {
    if (i < n && b[i] != i + 1) {
      d[c[i].first] = max(d[c[i].first], sz[c[i].first] - c[i].second);
    }
    if (i > 1 && e[i] != i - 1) {
      d[c[i].first] = max(d[c[i].first], sz[c[i].first] - c[i].second);
    }
  }
  int ans = 0;
  for (int i = 1; i <= k; ++i) {
    ans += (2 * d[i]);
  }
  printf("%d\n", ans + (k - 1));
}
