#include <bits/stdc++.h>
using namespace std;
vector<int> chains[110000];
int END[110000], C[110000];
void decompose(vector<int>& V) {
  int cost = 0;
  for (int i = 0; i < V.size();) {
    int j = i + 1;
    while (j < V.size() && V[j] == V[j - 1] + 1) j++;
    C[V[i]] = cost;
    END[V[i]] = V[j - 1];
    i = j;
    if (!cost) cost++;
  }
}
int main() {
  int n, k, m;
  scanf("%d %d", &n, &k);
  for (int i = 0; i < (k); i++) {
    scanf("%d", &m);
    chains[i] = vector<int>(m);
    for (int j = 0; j < (m); j++) scanf("%d", &chains[i][j]);
    decompose(chains[i]);
  }
  int s = 1;
  long long ans = 0;
  while (s <= n) {
    ans += C[s];
    if (END[s] < n) ans += 2 * (END[END[s] + 1] - END[s] - 1) + 1;
    s = END[s] + 1;
  }
  cout << ans << endl;
  return 0;
}
