#include <bits/stdc++.h>
using namespace std;
int main() {
  long long z = 0;
  int n, m, k, t;
  cin >> n >> m;
  vector<int> a;
  for (int i = 1; i <= m; i++) {
    a.clear();
    cin >> k;
    for (int j = 1; j <= k; j++) {
      cin >> t;
      a.push_back(t);
    }
    t = 0;
    if (a[0] == 1) t = 1;
    if (t == 1) {
      while (a[t] == t + 1 && t <= k - 1) t++;
      k = k - t + 1;
    }
    z += 2 * k - 1;
  }
  z--;
  cout << z;
}
