#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  int n, k, sum = 0;
  cin >> n >> k;
  while (k--) {
    int m;
    cin >> m;
    int a[m];
    for (int i = 0; i < m; i++) {
      cin >> a[i];
    }
    for (int i = 0; i < m; i++) {
      if (a[0] != 1) {
        sum += 2 * m - 1;
        break;
      } else if (a[i] != i + 1) {
        sum += 2 * (m - i);
        break;
      }
    }
  }
  cout << sum;
}
