#include <bits/stdc++.h>
using namespace std;
vector<int> datos[100001];
int main() {
  ios::sync_with_stdio(false);
  int n, k;
  cin >> n >> k;
  int ind = -1;
  for (int i = 0; i < k; i++) {
    int m;
    cin >> m;
    for (int j = 0; j < m; j++) {
      int x;
      cin >> x;
      datos[i].push_back(x);
      if (x == 1) {
        ind = i;
      }
    }
  }
  int new_ind = 0;
  for (int i = 1; i < datos[ind].size(); i++) {
    if (datos[ind][i] - datos[ind][i - 1] == 1) {
      new_ind = i;
    } else {
      break;
    }
  }
  int ans = 0;
  if (new_ind + 1 != datos[ind].size()) {
    ans = datos[ind].size() - (new_ind + 1);
    ans = ans * 2;
  }
  for (int i = 0; i < k; i++) {
    if (i == ind) {
      continue;
    }
    ans += 2 * datos[i].size() - 1;
  }
  cout << ans << endl;
}
