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.
//Done by Ferran Alet

#include<bits/stdc++.h>

#define INF 2147483647
#define LINF 1000000000000000000LL
#define EPS 1e-9
#define debug(x) //cerr << #x << " = " << x << endl
#define Debug(v) //cerr << #v << " = "; for(ll wow=0;wow<v.size();++wow) //cerr<<v[wow]<<' '; //cerr<<endl
#define DEBUG(M) //cerr << #M <<":"<<endl; for(ll iM=0;iM<M.size();++iM) { for(ll jM=0;jM<M[iM].size();++jM) //cerr<<M[iM][jM]<<' '; //cerr<<endl;} //cerr<<endl
#define FOR(x,y) for(ll x=0;x<y;x++)
#define FORS(x,y) for(ll x=0;x<ll(y.size());++x)
#define FORU(x,y) for(ll x=1;x<=y;x++)
#define RFOR(x,y) for(ll x=y-1;x>=0;--x)
#define DRI(x) ll x; cin>>x
#define DRII(x,y) ll x,y; cin>>x>>y
#define DRIII(x,y,z) ll x,y,z; cin>>x>>y>>z
#define PB push_back
#define SZ(X) ((ll)(X).size())
#define ALL(X) (X).begin(), (X).end()

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> PII;
typedef vector<ll> VI;
typedef vector<VI> VVI;
typedef vector<double> VD;
typedef vector<VD> VVD;
typedef vector<bool> VB;
typedef vector<VB> VVB;
typedef vector<char> VC;
typedef vector<VC> VVC;
typedef vector<string> VS;
typedef map<ll,ll> MII;
typedef MII::iterator iMII;
typedef vector<PII > VP;
typedef vector<VP> VVP;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
//  freopen(".out","w",stdout);
//  freopen(".in","r",stdin);
    ll n,m;
    while(cin>>n>>m){
      ll result=0;
      FOR(i,m){
        int a;
        cin>>a;
        VI v(a);
        FOR(i,a) cin>>v[i];
        int cont=0;
        while(cont<v.size() && v[cont]==cont+1) ++cont;
//         cerr<<cont<<' '<<result<<"==>";
        if(cont==0) result+=2*(a-cont)-1;
        else result+=2*(a-cont);
//         cerr<<result<<endl;
      }
      cout<<result<<endl;
    }
}