#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
int n, m;
int a[maxn];
int main() {
  while (~scanf("%d%d", &n, &m)) {
    int ans = 0;
    while (m--) {
      int k;
      scanf("%d", &k);
      for (int i = 1; i <= k; i++) {
        scanf("%d", &a[i]);
      }
      if (a[1] == 1) {
        int j = 0;
        for (int i = 2; i <= k; i++) {
          if (a[i] != i) {
            j = i;
            break;
          }
        }
        if (j) {
          ans += 2 * (k - j + 1);
        }
      } else {
        ans += 2 * k - 1;
      }
    }
    printf("%d\n", ans);
  }
  return 0;
}
