#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, ka, ans = 0, counter = 0;
  cin >> n >> ka;
  int i = 0, j, k;
  int t, t1, t2, set = 0;
  while (i < n) {
    set = 0;
    cin >> t;
    cin >> t1;
    for (j = 0; j < t - 1; j++) {
      cin >> t2;
      if (t2 != t1 + 1) set = 1;
      t1 = t2;
    }
    if (set != 0) {
      ans = ans + t - 1;
      counter = counter + t;
    } else
      counter = counter + 1;
    i = i + t;
  }
  cout << ans + counter - 1 << "\n";
  return 0;
}
