#include <bits/stdc++.h>
using namespace std;
long long const mod = 1000000007;
long long const md = 998244353;
long long mypowr(long long a, long long b) {
  long long res = 1;
  a %= mod;
  assert(b >= 0);
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % mod;
    a = a * a % mod;
  }
  return res;
}
long long mypow(long long a, long long b) {
  long long res = 1;
  assert(b >= 0);
  for (; b; b >>= 1) {
    if (b & 1) res = res * a;
    a = a * a;
  }
  return res;
}
ifstream in("beep.in");
ofstream out("beep.out");
int main() {
  cout << fixed << setprecision(12);
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(0);
  long long n, k;
  cin >> n >> k;
  long long cnt = 0, componente = 0;
  while (k--) {
    long long x;
    int f[100005];
    cin >> x;
    for (int i = 1; i <= x; ++i) {
      cin >> f[i];
    }
    if (f[1] != 1) {
      cnt += x - 1;
      componente += x;
    } else {
      int t = 2;
      int ans = 1;
      while (f[t] == f[t - 1] + 1) ++ans, ++t;
      x -= ans;
      cnt += x;
      componente += x + 1;
    }
  }
  cout << cnt + componente - 1 << '\n';
  return 0;
}
