#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
  if ((a == 0) || (b == 0)) return a + b;
  return gcd(b, a % b);
}
long long pow_mod(long long a, long long b) {
  long long res = 1;
  while (b) {
    if (b & 1) res = (res * a) % 1000000007;
    a = (a * a) % 1000000007;
    b >>= 1;
  }
  return res;
}
vector<int> D[100010];
long long arr[100010];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  long long N, i, j, K, time = 0, M, temp, kc, flag = 0;
  string st;
  cin >> N >> K;
  for (i = 0; i <= K - 1; i++) {
    cin >> M;
    arr[i] = M;
    for (j = 0; j <= M - 1; j++) {
      cin >> temp;
      if (temp == 1) {
        kc = i;
      }
      D[i].push_back(temp);
    }
  }
  long long h = D[kc].size();
  for (i = 0; i <= h - 1; i++) {
    if (D[kc][i] != (i + 1)) {
      flag = 1;
      break;
    }
  }
  if (flag == 1) {
    time += (arr[kc] - i) + (arr[kc] - i);
  }
  for (i = 0; i <= K - 1; i++) {
    if (i != kc) {
      time += (arr[i] - 1) + arr[i];
    }
  }
  cout << time;
  return 0;
}
