#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  vector<vector<int> > arr;
  vector<int> save(k, 1);
  vector<int> sum;
  for (int i = 0; i < k; i++) {
    int tmp;
    cin >> tmp;
    sum.push_back(tmp);
    vector<int> tmp_vec;
    for (int j = 0; j < tmp; j++) {
      int a;
      cin >> a;
      tmp_vec.push_back(a);
    }
    arr.push_back(tmp_vec);
  }
  for (int i = 0; i < k; i++) {
    bool flag = true;
    for (int j = 0; j < sum[i] - 1; j++) {
      if (flag && arr[i][j] == j + 1 && arr[i][j + 1] == j + 2)
        save[i]++;
      else
        flag = false;
    }
  }
  int ans = 0;
  int s = 0;
  for (int i = 0; i < k; i++) {
    s += (sum[i] - save[i] + 1);
    ans += (sum[i] - save[i]);
  }
  ans += (s - 1);
  cout << ans << endl;
  return 0;
}
