#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9;
const int MOD = 1e9 + 7;
const int N = 2e5 + 10;
int n, m, m1, x;
pair<int, int> pos[N];
vector<int> a[N];
int main() {
  scanf("%d%d", &n, &m);
  for (auto i = 1; i <= m; i++) {
    scanf("%d", &m1);
    for (auto j = 0; j < m1; j++) {
      scanf("%d", &x);
      a[i].push_back(x);
      pos[x] = pair<int, int>(i, j);
    }
  }
  int ans = 0;
  for (auto i = 1; i <= n; i++) {
    int col = pos[i].first, re = pos[i].second;
    int m1 = a[col].size();
    if (i == 1)
      while (re < m1 - 1 && a[col][re + 1] == i + 1) re++, i++;
    for (auto j = m1 - 1; j >= re + 1; j--) {
      ans++;
      int x = a[col].back();
      a[col].pop_back();
      a[++m].push_back(x);
      pos[x] = pair<int, int>(m, 0);
    }
    a[col].pop_back();
    ans++;
  }
  cout << ans - 1;
}
