#include <bits/stdc++.h>
const long long inf = 1000000000ll;
const long long inf64 = inf * inf;
const long long base = inf + 7;
const double pi = acos(-1.0);
using namespace std;
template <typename T, typename P>
const ostream& operator<<(ostream& os, const pair<T, P>& a) {
  os.precision(10);
  os << fixed;
  os << "{";
  os << a.first;
  os << ' ';
  os << a.second;
  os << "} ";
  return os;
}
bool solve() {
  int n, k, m;
  scanf("%d %d", &n, &k);
  long long ans = 0;
  vector<pair<int, int> > mas;
  for (int i(0); i < k; i++) {
    scanf("%d", &m);
    vector<int> a(m);
    for (int j(0); j < m; j++) scanf("%d", &a[j]);
    int pos = 0;
    while (pos + 1 < m && a[pos] + 1 == a[pos + 1]) pos++;
    ans += m - (pos + 1);
    mas.push_back(make_pair(a[0], a[pos]));
    for (int j(pos + 1); j < m; j++) mas.push_back(make_pair(a[j], a[j]));
  }
  sort((mas).begin(), (mas).end());
  for (int i(0); i + 1 < (int)mas.size(); i++) {
    ans += mas[i + 1].second - mas[i + 1].first;
    ans += mas[i + 1].second - mas[i + 1].first + 1;
  }
  cout << ans << '\n';
  return true;
}
int main() {
  solve();
  return 0;
}
