#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool fs(T &x) {
  int c = getchar();
  int sgn = 1;
  while (~c && c < '0' || c > '9') {
    if (c == '-') sgn = -1;
    c = getchar();
  }
  for (x = 0; ~c && '0' <= c && c <= '9'; c = getchar()) x = x * 10 + c - '0';
  x *= sgn;
  return ~c;
}
int main() {
  int a, b, n, m, x, prev, now, cnt = 0;
  fs(n);
  fs(m);
  set<int> st;
  vector<int> num;
  for (int i = 0; i < m; i++) {
    fs(x);
    fs(prev);
    if (x == 1) num.push_back(prev);
    st.insert(prev);
    for (int j = 0; j < x - 1; j++) {
      fs(now);
      st.insert(now);
      if (now - 1 != prev) {
        num.push_back(prev);
        cnt++;
      }
      prev = now;
    }
    if (x > 1) num.push_back(now);
  }
  sort((num).begin(), (num).end());
  int sum = 0;
  for (int i = 1; i < num.size(); i++) sum += (2 * (num[i] - num[i - 1]) - 1);
  cout << sum + cnt + n - st.size() << endl;
  return 0;
}
