#include <bits/stdc++.h>
using namespace std;
long long binpow(long long a, long long n) {
  long long b = 1;
  while (n > 0) {
    if (n & 1) b *= a;
    a *= a;
    n >>= 1;
  }
  return b;
}
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
vector<int> a;
vector<vector<int>> v;
long long res = 0;
void merge(vector<int> &a, vector<int> &b, vector<int> &c) {
  int ai = 0, bi = 0, ci = 0;
  while (bi != b.size() && ci != c.size()) {
    if (b[bi] < c[ci])
      a[ai++] = b[bi++];
    else {
      res += b.size() - bi;
      a[ai++] = c[ci++];
    }
  }
  while (bi != b.size()) a[ai++] = b[bi++];
  while (ci != c.size()) a[ai++] = c[ci++];
}
void MergeSort(vector<int> &a) {
  if (a.size() <= 1) return;
  int k = a.size() / 2;
  vector<int> b = vector<int>(a.begin(), a.begin() + k);
  vector<int> c = vector<int>(a.begin() + k, a.end());
  MergeSort(b);
  MergeSort(c);
  res++;
  merge(a, b, c);
}
int main() {
  int n;
  int k;
  long long sum = 0;
  int len = 0;
  cin >> n >> k;
  res = 0;
  v.resize(k + 1);
  for (int i = 0; i < k; i++) {
    int t, temp;
    cin >> t;
    sum += t;
    for (int j = 0; j < t; j++) {
      cin >> temp;
      v[i].push_back(temp);
    }
    int tres = res;
    if (v[i].size() != 1) {
      for (int j = 0; j < v[i].size(); j++) {
        if (v[i][j] == 1) {
          len = 1;
          while (j + 1 < v[i].size() && v[i][j] + 1 == v[i][j + 1]) {
            j++;
            len++;
          }
        }
        if (j) res++;
      }
      if (tres == res && v[i][v[i].size() - 1] != n) res++;
    }
  }
  long long result = sum + res - 1;
  if (len > 1) result -= len;
  cout << result << endl;
  return 0;
}
