#include <bits/stdc++.h>
using namespace std;
const int MAX = 100005;
const int oo = 1e9 + 7;
const long long mod = 1e11 + 7;
const double eps = 1e-9;
const double pi = acos(-1);
int n, k, mi, hi;
int main() {
  cin.sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> k;
  int ans = 0;
  for (int i = 0; i < k; i++) {
    cin >> mi;
    int next;
    bool yes = true;
    for (int j = 0; j < mi; j++) {
      cin >> hi;
      if (hi == 1) {
        yes = false;
        next = 2;
        for (int k = 1; k < mi; k++) {
          cin >> hi;
          if (hi != next) {
            ans += 2;
            next = -1987;
          } else
            next++;
        }
        break;
      }
    }
    if (yes == true) ans += (2 * mi - 1);
  }
  cout << ans << endl;
}
