#include <bits/stdc++.h>
using namespace std;
int s[100005];
int a[100005];
int main() {
  int n, k;
  cin >> n >> k;
  int ans = 0;
  int parts = 0;
  for (int i = 0; i < k; i++) {
    scanf("%d", &s[i]);
    for (int j = 0; j < s[i]; j++) {
      scanf("%d", &a[j]);
    }
    int t = 0, flag = 1;
    for (int j = 0; j < s[i]; j++) {
      if (flag && a[j] == j + 1) {
        t = 1;
        continue;
      }
      t++;
      flag = 0;
    }
    ans += t - 1;
    parts += t;
  }
  ans += parts - 1;
  cout << ans << endl;
  return 0;
}
