#include <bits/stdc++.h>
using namespace std;
int a[100005];
int main() {
  int n, m;
  cin >> n >> m;
  int s = 0;
  int cnt;
  int sum = 0;
  for (int t = 1; t <= m; t++) {
    int x;
    cin >> x;
    cnt = 0;
    for (int j = 1; j <= x; j++) {
      scanf("%d", &a[j]);
    }
    for (int j = 2; j <= x; j++) {
      if (a[j] == j) {
        continue;
      } else {
        s++;
        cnt++;
      }
    }
    sum += cnt + 1;
  }
  cout << s + sum - 1 << endl;
  return 0;
}
