#include <bits/stdc++.h>
using namespace std;
const int N = 2 * 100000 + 5;
const long long int MOD = 1000000007;
int main() {
  int n, k;
  cin >> n >> k;
  int ans = 0;
  vector<int> vec[N];
  int cnt = 0;
  for (int i = 0; i < k; i++) {
    int m;
    cin >> m;
    for (int z = 0; z < m; z++) {
      int tmp;
      cin >> tmp;
      vec[i].push_back(tmp);
    }
    if (vec[i][0] == 1) {
      int ken = 0, z = 1;
      while (z < vec[i].size() && vec[i][z] == z + 1) {
        ken++;
        z++;
      }
      m -= ken;
    }
    ans += m - 1;
    cnt += m;
  }
  ans += cnt - 1;
  cout << ans;
}
