#include <bits/stdc++.h>
using namespace std;
vector<int> a[100005];
int main() {
  int n, m;
  cin >> n >> m;
  int te;
  for (int i = 0; i < m; i++) {
    scanf("%d", &te);
    a[i].push_back(te);
    for (int j = 1; j <= a[i][0]; j++) {
      scanf("%d", &te);
      a[i].push_back(te);
    }
  }
  int t;
  long long int sum = 0;
  for (int i = 0; i < m; i++) {
    te = a[i][0];
    if (a[i][1] == 1) {
      for (int j = 1;; j++) {
        if (a[i][j] != j) {
          t = j - 1;
          sum += a[i][0] - j + 1;
          break;
        }
        if (j == a[i][0]) {
          t = j;
          break;
        }
      }
    } else {
      sum += a[i][0] - 1;
    }
  }
  sum += n - t;
  cout << sum << endl;
  return 0;
}
