#include <bits/stdc++.h>
using namespace std;
const long long linf = 1e18 + 5;
const int mod = 1e9 + 7;
const int logN = 18;
const int inf = 1e9;
const int N = 2e5 + 5;
int n, k, x, t, ans, a[N], gr;
int main() {
  cin >> n >> k;
  int ans = 0;
  int mn = inf, ss = 0;
  for (int i = 1; i <= k; i++) {
    scanf("%d", &t);
    int last = inf;
    int size = 0;
    for (int j = 1; j <= t; j++) scanf("%d", &a[j]);
    for (int j = 1; j <= t; j++) {
      int tt = j;
      while (tt + 1 <= t && a[tt] == a[tt + 1] - 1) tt++;
      ans += tt - j;
      if (a[j] < mn) {
        mn = a[j];
        ss = tt - j;
      }
      j = tt;
      ans++;
    }
    ans--;
  }
  cout << ans - 2 * ss + n - 1 << '\n';
  return 0;
}
