#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > g;
int a[1234567];
int main() {
  int n, k;
  scanf("%d %d", &n, &k);
  long long res = 0;
  for (int i = 0; i < k; ++i) {
    int m;
    scanf("%d", &m);
    for (int j = 0; j < m; ++j) {
      scanf("%d", &a[j]);
    }
    vector<int> net;
    net.push_back(a[m - 1]);
    for (int j = m - 1; j >= 1; --j) {
      if (a[j] == a[j - 1] + 1) {
        net.push_back(a[j - 1]);
      } else {
        if (net.empty()) continue;
        sort(net.begin(), net.end());
        g.push_back(net);
        res++;
        net.clear();
        net.push_back(a[j - 1]);
      }
    }
    if (!net.empty()) {
      sort(net.begin(), net.end());
      g.push_back(net);
      net.clear();
    }
  }
  sort(g.begin(), g.end(),
       [](vector<int>& a, vector<int>& b) { return a[0] < b[0]; });
  for (int i = 1; i < (int)g.size(); ++i) {
    res += ((((int)g[i].size()) - 1) * 2LL + 1);
  }
  printf("%lld\n", res);
  return (0);
}
