Andrewid the Android is a galaxy-famous detective. He is now investigating the case of vandalism at the exhibition of contemporary art.

The main exhibit is a construction of *n* matryoshka dolls that can be nested one into another. The matryoshka dolls are numbered from 1 to *n*. A matryoshka with a smaller number can be nested in a matryoshka with a higher number, two matryoshkas can not be directly nested in the same doll, but there may be chain nestings, for example, 1 → 2 → 4 → 5. 

In one second, you can perform one of the two following operations:
 -  Having a matryoshka *a* that isn't nested in any other matryoshka and a matryoshka *b*, such that *b* doesn't contain any other matryoshka and is not nested in any other matryoshka, you may put *a* in *b*; -  Having a matryoshka *a* directly contained in matryoshka *b*, such that *b* is not nested in any other matryoshka, you may get *a* out of *b*. 
According to the modern aesthetic norms the matryoshka dolls on display were assembled in a specific configuration, i.e. as several separate chains of nested matryoshkas, but the criminal, following the mysterious plan, took out all the dolls and assembled them into a single large chain (1 → 2 → ... → *n*). In order to continue the investigation Andrewid needs to know in what minimum time it is possible to perform this action.
The first line contains integers *n* (1 ≤ *n* ≤ 10<sup class="upper-index">5</sup>) and *k* (1 ≤ *k* ≤ 10<sup class="upper-index">5</sup>) — the number of matryoshkas and matryoshka chains in the initial configuration.

The next *k* lines contain the descriptions of the chains: the *i*-th line first contains number *m*<sub class="lower-index">*i*</sub> (1 ≤ *m*<sub class="lower-index">*i*</sub> ≤ *n*), and then *m*<sub class="lower-index">*i*</sub> numbers *a*<sub class="lower-index">*i*1</sub>, *a*<sub class="lower-index">*i*2</sub>, ..., *a*<sub class="lower-index">*im*<sub class="lower-index">*i*</sub></sub> — the numbers of matryoshkas in the chain (matryoshka *a*<sub class="lower-index">*i*1</sub> is nested into matryoshka *a*<sub class="lower-index">*i*2</sub>, that is nested into matryoshka *a*<sub class="lower-index">*i*3</sub>, and so on till the matryoshka *a*<sub class="lower-index">*im*<sub class="lower-index">*i*</sub></sub> that isn't nested into any other matryoshka).

It is guaranteed that *m*<sub class="lower-index">1</sub> + *m*<sub class="lower-index">2</sub> + ... + *m*<sub class="lower-index">*k*</sub> = *n*, the numbers of matryoshkas in all the chains are distinct, in each chain the numbers of matryoshkas follow in the ascending order.
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#define For(i, a, b)  for(int i = a; i < b; ++i)
#define mp make_pair
#define x first
#define y second
#define point pair <int, int>
#define read(s1, s2); freopen(s1, "r", stdin); freopen(s2, "w", stdout);

using namespace std;

int n, k;
int arr[100001];
vector <int> ans[100001];
int cnt;

main() {
    cin >> n >> k;
    For(i, 0, k) {
        int s;
        cin >> s;
        For(j, 0, s) {
            int a;
            cin >> a;
            ans[i].push_back(n - a);
            arr[n - a] = i;
        }
    }
    For(i, 0, n) {
        if (ans[arr[i]].size() == n - i) {
            break;
        }
        //cout << cnt << endl;
        cnt += ans[arr[i]].size() != 1;
        ++cnt;
        //cout << cnt << endl;
        ans[arr[i]].pop_back();
    }
    cout << cnt;
}






