#include <bits/stdc++.h>
using namespace std;
vector<int> v[200005];
int main() {
  int n, k;
  cin >> n >> k;
  int tot = 1, ans = 0;
  for (int i = (int)1; i <= (int)k; i++) {
    int m;
    cin >> m;
    for (int j = (int)1; j <= (int)m; j++) {
      int x;
      cin >> x;
      v[i].push_back(x);
    }
    int l = v[i][0], r = 1;
    if (l != 1) {
      ans += m - 1;
      tot += m;
      continue;
    }
    for (int j = (int)1; j <= (int)m - 1; j++) {
      if (v[i][j] != l + 1) {
        break;
      }
      r++;
      l = v[i][j];
    }
    tot += m - r + 1;
    ans += m - r;
  }
  tot--;
  ans += tot - 1;
  cout << ans << endl;
}
