#include <bits/stdc++.h>
using namespace std;
long long n, m, x, y, z, k, sol, sum, ans, l, r, xx, yy, a[1000000], b[1000000];
vector<long long> v;
vector<long long> v1;
vector<long long> v2;
pair<long long, pair<long long, long long> > pp[1000000];
pair<long long, long long> p[1000000];
map<long long, long long> ma;
string s1, s2, s;
char c;
int main() {
  cin >> n >> k;
  sum = 0;
  for (int i = 0; i < k; i++) {
    cin >> m;
    for (int q = 1; q <= m; q++) {
      cin >> a[q];
    }
    if (a[1] == 1) {
      for (int q = 2; q <= m; q++) {
        if (a[q] - 1 != a[q - 1]) {
          sum += m - q + 1;
          x += (m - q + 1);
          break;
        }
      }
    } else {
      sum += (m - 1);
      x += m;
    }
  }
  sum += x;
  cout << sum << endl;
  return 0;
}
