#include <bits/stdc++.h>
using namespace std;
const int M = 100005;
int n, m[M], x, y, a[M], k, pre, c;
long long sum;
vector<vector<int> > v;
string s, z;
int main() {
  cin >> n >> k;
  v.resize(k);
  for (int i = 0; i < k; i++) {
    scanf("%d", &m[i]);
    int idx = m[i];
    bool f = false, f1 = false, f2 = false;
    for (int j = 0; j < m[i]; j++) {
      scanf("%d", &a[j]);
      if (a[0] == 1) f = true;
      if (j && f && a[j] - 1 == a[j - 1] && !f2)
        c++;
      else if (j && f && a[j] - 1 != a[j - 1] && !f2)
        idx = j, f2 = true;
    }
    if (f) {
      sum += (m[i] - idx);
      pre = i;
    }
  }
  for (int i = 0; i < k; i++) {
    if (i == pre)
      continue;
    else
      sum += (m[i] - 1);
  }
  c++;
  sum += (n - 1);
  sum -= (c - 1);
  cout << sum;
  return 0;
}
