#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  int n, k;
  cin >> n >> k;
  int ret = 0;
  for (int a = 0; a < k; ++a) {
    int m;
    cin >> m;
    int q;
    cin >> q;
    if (q == 1) {
      int c = 1, l = 1;
      for (int b = 1; b < m; ++b) {
        cin >> q;
        if (q == l + 1)
          ++c;
        else {
          for (++b; b < m; ++b) cin >> q;
        }
        l = q;
      }
      ret += 2 * (m - c);
    } else {
      for (int b = 1; b < m; ++b) cin >> q;
      ret += m - 1 + m;
    }
  }
  cout << ret;
  return 0;
}
