#include <bits/stdc++.h>
using namespace std;
const long long nmax = 100010;
const long long mod = 1e9 + 7;
const long long inf = 3 * 1e9;
vector<vector<int> > v;
int main() {
  int n, k;
  cin >> n >> k;
  v.assign(n + 5, vector<int>());
  long long ans = 0;
  for (int i = 0; i < k; ++i) {
    int m;
    cin >> m;
    int l;
    for (int j = 0; j < m; ++j) {
      int s;
      int dop;
      if (j) dop = v[l].back();
      cin >> s;
      if (!j) l = s;
      v[l].push_back(s);
      if (j) {
        if (v[l].back() != dop + 1) {
          v[v[l].back()].push_back(v[l].back());
          v[l].pop_back();
          ans++;
        }
      }
    }
  }
  long long res = 0;
  for (int i = 1; i <= n; ++i) {
    if (!v[i].empty()) res++;
  }
  cout << ans + res - 1 << '\n';
  return 0;
}
