#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0), cout.tie(0), cout.precision(15);
  int n, k;
  cin >> n >> k;
  int count = 0, time = 0;
  int mcount = 0;
  int f = 0;
  for (int i = 0; i < k; i++) {
    int x;
    cin >> x;
    int arr[100005];
    for (int i = 0; i < x; i++) cin >> arr[i];
    count = 0;
    time += x - 1;
    for (int i = 0; i < x; i++) {
      if (arr[i] == i + 1) {
        count++;
      } else {
        break;
      }
    }
    mcount = max(mcount, count);
  }
  cout << n - 1 + time - 2 * (mcount - 1);
}
