#include <bits/stdc++.h>
using namespace std;
int old, ne, res, rr;
int n, k, m, d[100005];
int main() {
  cin >> n >> k;
  for (int i = 1; i <= k; i++) {
    cin >> m;
    cin >> old;
    d[i] = 1;
    for (int j = 2; j <= m; j++) {
      cin >> ne;
      if ((ne - 1) != old) ++d[i];
      old = ne;
    }
  }
  for (int i = 1; i <= k; i++) {
    res += d[i] - 1;
    rr += d[i];
  }
  res += rr - 1;
  cout << res;
}
