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.


-----Input-----

The first line contains integers n (1 ≤ n ≤ 10^5) and k (1 ≤ k ≤ 10^5) — 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_{i} (1 ≤ m_{i} ≤ n), and then m_{i} numbers a_{i}1, a_{i}2, ..., a_{im}_{i} — the numbers of matryoshkas in the chain (matryoshka a_{i}1 is nested into matryoshka a_{i}2, that is nested into matryoshka a_{i}3, and so on till the matryoshka a_{im}_{i} that isn't nested into any other matryoshka).

It is guaranteed that m_1 + m_2 + ... + m_{k} = n, the numbers of matryoshkas in all the chains are distinct, in each chain the numbers of matryoshkas follow in the ascending order.


-----Output-----

In the single line print the minimum number of seconds needed to assemble one large chain from the initial configuration.


-----Examples-----
Input
3 2
2 1 2
1 3

Output
1

Input
7 3
3 1 3 7
2 2 5
2 4 6

Output
10



-----Note-----

In the first sample test there are two chains: 1 → 2 and 3. In one second you can nest the first chain into the second one and get 1 → 2 → 3.

In the second sample test you need to disassemble all the three chains into individual matryoshkas in 2 + 1 + 1 = 4 seconds and then assemble one big chain in 6 seconds.

```python

USER_FILENAME = "<user_code>"
import sys, json, builtins
import math, heapq, bisect, itertools, functools, collections, statistics, fractions, decimal, operator, array, random, re, string, os, pathlib
try:
    import resource as _res
except Exception:
    _res = None
from collections import Counter, defaultdict, deque, OrderedDict
from functools import lru_cache, reduce
from itertools import accumulate, permutations, combinations, product
from math import gcd, ceil, floor, sqrt
from decimal import Decimal
try:
    from typing import *
except Exception:
    pass
try:
    sys.setrecursionlimit(1_000_000)
except Exception:
    pass
try:
    import site as _site
    try:
        _sys_sites = _site.getsitepackages() if hasattr(_site, "getsitepackages") else []
        for _p in _sys_sites:
            if _p and _p not in sys.path:
                sys.path.append(_p)
    except Exception:
        pass
    try:
        _usp = _site.getusersitepackages()
        if isinstance(_usp, str):
            _usp = [_usp]
        for _p in _usp:
            if _p and _p not in sys.path:
                sys.path.append(_p)
    except Exception:
        pass
except Exception:
    pass

ns = {"__name__": "__main__"}
for _k, _v in list(globals().items()):
    if not _k.startswith("_"):
        ns[_k] = _v
_CODE = "##row, col, order = input().split(' ')    \n##row = int(row)\n##col = int(col)\n##\n##init_list = []\n##\n##for i in range(row):\n##    init_list.append(input().split(' '))\n##\n##if order=='0':\n##    for i in range(row):\n##        print()\n##        for j in range(col,0,-1):\n##            print(init_list[i][j-1], end = ' ')\n##else:\n##    for i in range(row,0,-1):\n##        print()\n##        for j in range(col):\n##            print(init_list[i-1][j], end = ' ')\n\ndef judge(_list:list) -> int:\n    number = -1\n    for i in range(len(_list)):\n        if int(_list[i]) == i+1:\n            number += 1\n        else:\n            pass\n    \n    return number\n\nmat_num, chain_num = input().split(' ')\nmat_num, chain_num = int(mat_num), int(chain_num)\n\nchain = []\n\nfor i in range(chain_num):\n    chain.append([])\n    temp_list = input().split(' ')\n    for j in range(int(temp_list[0])):\n        chain[-1].append(temp_list[1])\n        del temp_list[1]\n\nfor i in range(chain_num):\n    if judge(chain[i]) < 1:\n        pass\n    else:\n        temp_count = len(chain[i]) - judge(chain[i])\n        chain[i] = []\n        for j in range(temp_count):\n            chain[i].append(1)\n\ntime = 0\ncount = 0\n\nfor i in range(chain_num):\n    time += len(chain[i]) - 1\n    count += len(chain[i])\n\nprint(time + count -1)\n"
_co = compile(_CODE, USER_FILENAME, "exec")
exec(_co, ns, ns)

```

Measured memory_bytes: 13733