#include <bits/stdc++.h>
using namespace std;
const int N = (int)5e5 + 7;
const int INF = 1e9 + 7;
const long double EPS = 1e-7;
int a[N];
int main() {
  int n, k, x, y, a, sum = 0;
  cin >> n >> k;
  for (int i = 0; i < k; i++) {
    scanf("%d", &x);
    sum += x + x - 1;
    scanf("%d", &y);
    bool flag = bool(y == 1);
    for (int i = 1; i < x; i++) {
      scanf("%d", &a);
      if (flag && a - y != 1)
        flag = false;
      else if (flag)
        sum -= 2;
      y = a;
    }
  }
  cout << sum - 1;
  return 0;
}
