#include <bits/stdc++.h>
using namespace std;
int sol;
void leer() {
  int m, a, b, aux;
  cin >> m;
  if (m < 2) {
    cin >> a;
    sol++;
    return;
  }
  aux = m;
  cin >> b;
  cin >> a;
  m--;
  m--;
  while (b + 1 == a and m--) {
    aux--;
    b = a;
    cin >> a;
  }
  if (m > 0)
    while (m--) cin >> a;
  else if (b + 1 == a)
    aux--;
  sol += aux * 2 - 1;
}
int main() {
  int n, k;
  cin >> n >> k;
  while (k--) leer();
  cout << sol - 1 << endl;
}
