#include <bits/stdc++.h>
using namespace std;
int const MAX_N = 200100 * 2;
int const MAX_Q = 410100;
int const MAX_CH = 410100;
long long const LL_INF = 1000000000000000009LL;
int cur_chain[MAX_N];
int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  long long ans = 0;
  long long all_sgm_count = 0;
  for (int i = 0; i < k; i++) {
    int len;
    scanf("%d", &len);
    for (int j = 0; j < len; j++) scanf("%d", &cur_chain[j]);
    if (len > 0 && cur_chain[0] == 1) {
      int max_not_beat = 1;
      for (int j = 1; j < len; j++) {
        if (cur_chain[j] != cur_chain[j - 1] + 1) break;
        max_not_beat++;
      }
      ans += len - max_not_beat;
      all_sgm_count += len - max_not_beat + 1;
    } else if (len > 0) {
      ans += len - 1;
      all_sgm_count += len;
    }
  }
  ans += max(0LL, all_sgm_count - 1LL);
  cout << ans;
  return 0;
}
