#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 6;
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  long long ans = 0;
  int c2 = 0;
  for (int k = 0; k < m; ++k) {
    int d;
    scanf("%d", &d);
    vector<int> b;
    int p = 1;
    for (int i = 0; i < d; ++i) {
      int x;
      scanf("%d", &x);
      if (b.size() && b.back() == p && x == p + 1)
        b.back() = x, ++p;
      else
        b.push_back(x);
    }
    ans += b.size() - 1;
    c2 += b.size();
  }
  ans += c2 - 1;
  cout << ans << endl;
  return 0;
}
