#include <bits/stdc++.h>
using namespace std;
vector<int> adj[100010];
int res;
void go_del(int v) {
  if (adj[v].size() == 0) return;
  int w = adj[v][0];
  adj[v].pop_back();
  res++;
  go_del(w);
}
int main() {
  int n, m, k, val;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> k;
    int ant = -1;
    for (int ii = 0; ii < k; ii++) {
      cin >> val;
      if (ant != -1) {
        adj[ant].push_back(val);
      }
      ant = val;
    }
  }
  res = 0;
  for (int i = 1; i < n; i++) {
    int cur = i;
    int next_cur = i + 1;
    if (adj[cur].size() == 0) {
      if (adj[next_cur].size() == 0)
        res++;
      else {
        res++;
        go_del(next_cur);
      }
    } else {
      if (adj[cur][0] == next_cur)
        continue;
      else {
        res++;
        go_del(cur);
        go_del(next_cur);
      }
    }
  }
  cout << res << endl;
  return 0;
}
