#include <bits/stdc++.h>   int n, k, m, c, arr[100005], ans;   inline void check() {     int i = 0;     while (i < m) {       if (arr[i] == i + 1)         i++;       else         break;     }     if (i)       c += (m - i + 1), ans += (m - i);     else       c += m, ans += (m - 1);   }   int main() {     scanf( %d %d , &n, &k);     ans = c = 0;     while (k--) {       scanf( %d , &m);       for (int i = 0; i < m; ++i) scanf( %d , &arr[i]);       check();     }     ans += (c - 1);     printf( %d , ans);     return 0;   }   