func_code_string: #include <bits/stdc++.h>   using namespace std;   long long INF = 1e9;   const int maxn = 1e6 + 5;   int a[maxn];   int tpr = 0;   vector<int> adj[maxn];   void dfs(int root) {     if (adj[root].size() > 0) {       if (adj[root][0] == (root + 1)) {         dfs(root + 1);         tpr++;       } else         return;     }   }   int main() {     int n, m, t, i, j, k;     int flag = 0, flag2;     int ans = 0;     cin >> n >> k;     for (int i = 0; i < k; i++) {       cin >> m;       ans += m - 1;       int y;       int prev = -1;       for (int j = 0; j < m; j++) {         cin >> y;         if (y == 1) {           flag2 = m - 1;         }         if ((j == 0) && (y == 1)) {           flag = 1;         }         if (prev != -1) adj[prev].push_back(y);         prev = y;       }     }     if (flag == 0) {       ans += n - 1;       cout << ans << endl;       return 0;     }     dfs(1);     ans -= tpr;     ans += (n - tpr - 1);     cout << ans << endl;     return 0;     return 0;   }   