#include <bits/stdc++.h>
using namespace std;
bool f(long long int mid, long long int k, long long int n) {
  long long int sum = 0, p = 1;
  while (1) {
    sum = sum + (mid / p);
    p = p * k;
    if (sum >= n) return 1;
    if (mid / p == 0) break;
  }
  return 0;
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  ;
  int n, k;
  cin >> n >> k;
  long long int sum = n - 1;
  for (int i = 0; i < k; i++) {
    int t;
    cin >> t;
    vector<int> v;
    bool f = 0;
    for (int j = 0; j < t; j++) {
      int tt;
      cin >> tt;
      if (tt == 1) f = 1;
      v.push_back(tt);
    }
    int c = 0, c1 = 0;
    if (f) {
      for (int i = 0; i < v.size();) {
        if (v[i] != 1) {
          c++;
          i++;
          continue;
        } else {
          while (i < v.size() - 1 && v[i + 1] == v[i] + 1) {
            c1++;
            i++;
          }
          i++;
        }
      }
      if (c1 == 0)
        sum += (t - 1);
      else {
        sum -= c1, sum += c;
      }
    } else
      sum += (t - 1);
  }
  cout << sum << endl;
  return 0;
}
