Sereja is a coder and he likes to take part in Codesorfes rounds. However, Uzhland doesn't have good internet connection, so Sereja sometimes skips rounds.

Codesorfes has rounds of two types: Div1 (for advanced coders) and Div2 (for beginner coders). Two rounds, Div1 and Div2, can go simultaneously, (Div1 round cannot be held without Div2) in all other cases the rounds don't overlap in time. Each round has a unique identifier — a positive integer. The rounds are sequentially (without gaps) numbered with identifiers by the starting time of the round. The identifiers of rounds that are run simultaneously are different by one, also the identifier of the Div1 round is always greater.

Sereja is a beginner coder, so he can take part only in rounds of Div2 type. At the moment he is taking part in a Div2 round, its identifier equals to x. Sereja remembers very well that he has taken part in exactly k rounds before this round. Also, he remembers all identifiers of the rounds he has taken part in and all identifiers of the rounds that went simultaneously with them. Sereja doesn't remember anything about the rounds he missed.

Sereja is wondering: what minimum and what maximum number of Div2 rounds could he have missed? Help him find these two numbers.


-----Input-----

The first line contains two integers: x (1 ≤ x ≤ 4000) — the round Sereja is taking part in today, and k (0 ≤ k < 4000) — the number of rounds he took part in.

Next k lines contain the descriptions of the rounds that Sereja took part in before. If Sereja took part in one of two simultaneous rounds, the corresponding line looks like: "1 num_2 num_1" (where num_2 is the identifier of this Div2 round, num_1 is the identifier of the Div1 round). It is guaranteed that num_1 - num_2 = 1. If Sereja took part in a usual Div2 round, then the corresponding line looks like: "2 num" (where num is the identifier of this Div2 round). It is guaranteed that the identifiers of all given rounds are less than x.


-----Output-----

Print in a single line two integers — the minimum and the maximum number of rounds that Sereja could have missed.


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

Output
0 0
Input
9 3
1 2 3
2 8
1 4 5

Output
2 3
Input
10 0

Output
5 9


-----Note-----

In the second sample we have unused identifiers of rounds 1, 6, 7. The minimum number of rounds Sereja could have missed equals to 2. In this case, the round with the identifier 1 will be a usual Div2 round and the round with identifier 6 will be synchronous with the Div1 round. 

The maximum number of rounds equals 3. In this case all unused identifiers belong to usual Div2 rounds.

Difficulty: interview

Starter code:

Solutions:
X,n=list(map(int,input().split()))


Taken=[True]*(X+1)
for i in range(n):
    x=list(map(int,input().split()))
    if(x[0]==1):
        Taken[x[1]]=False
        Taken[x[2]]=False
    else:
        Taken[x[1]]=False
cnt=0
minn=0
maxx=0
ans=0
for i in range(1,X):
    if(Taken[i]):
        cnt+=1
        maxx+=1
    else:
        ans+=cnt//2
        if(cnt%2!=0):
            ans+=1
        cnt=0
ans+=cnt//2
if(cnt%2!=0):
    ans+=1
print(ans,maxx)


x, k = map(int, input().split())
a = [1] * x
for i in range(k):
    s = input().split()
    if s[0] == '1':
        a[int(s[1])] = 0
        a[int(s[2])] = 0
    else:
        a[int(s[1])] = 0
i = 1
t = 0
while i < x:
    if a[i] == 1:
        if i + 1 < x and a[i + 1] == 1:
            t += 1
        i += 2
    else:
        i += 1
print(sum(a[1:]) - t, sum(a[1:]))

def main():
	x, k = map(int, input().split())
	A = [0] * x
	mx = x - 1
	for i in range(k):
		s = list(map(int, input().split()))
		A[s[1] - 1] = 1
		if len(s) == 3:
			A[s[2] - 1] = 1
		mx -= len(s) - 1
	mn = 0
	for i in range(x - 1):
		if A[i] == 0:
			mn += 1
			if A[i + 1] == 0:
				A[i + 1] = 1
	print(mn, mx)


main()

x,k=list(map(int,input().split()))
s=set()
for i in range(k):
    a=list(map(int,input().split()))
    if a[0]==1:
        s.add(a[1])
        s.add(a[2])
    else:
        s.add(a[1])
smax=set()
smin=set()
for i in range(1,x):
    if not i in s and not i+1 in s and not i in smin:
        smin.add(i+1)
    if not i in s:
        smax.add(i)
    if not i in s and i+1 in s:
        smin.add(i)
print(len(smin),len(smax))


#!/usr/bin/env python3

def read_ints():
	return list(map(int, input().strip().split()))
	
t, k = read_ints()

all = []

for _ in range(k):
	avail = list(read_ints())
	for x in avail[1:]:
		all.append(x)

all.sort()

res_min, res_max = 0, 0

last = 0
for num in all:
	d = num-last
	res_min += (d)//2
	res_max += d-1

	last = num

d = t-last
res_min += (d)//2
res_max += d-1

print(res_min, res_max)


x, k = map(int, input().split())
rounds = [False for i in range(x + 1)]
for i in range(k):
    line = list(map(int, input().split()))
    if line[0] == 1:
        rounds[line[1]] = True
        rounds[line[2]] = True
    else:
        rounds[line[1]] = True
maximum = rounds[1:x].count(False)
minimum = 0
i = x - 1
while i > 0:
    if i > 1 and rounds[i] == False and rounds[i - 1] == False:
        i -= 2
        minimum += 1
    elif rounds[i] == False:
        i -= 1
        minimum += 1
    else:
        i -= 1
print(minimum, maximum)

import sys

f = sys.stdin
# f = open("input.txt", "r")

x, k = map(int, f.readline().strip().split())

a = []

for i in range(k):
    a += list(map(int, f.readline().strip().split()))[1:]

a.sort()

sub = list(set(range(1, x)) - set(a))

max = len(sub)

i = 0

sync = 0
while i < len(sub)-1:
    if sub[i+1] - sub[i] == 1:
        i += 1
        sync += 1
    i += 1

min = max - sync

print(min, max)

#!/usr/bin/env python3


def main():
    x, t = list(map(int, input().split()))
    markers = [1] * (x - 1)
    for c in range(t):
        r = [int(n) for n in input().split()]
        markers[r[1] - 1] = 0
        if r[0] == 1:
            markers[r[2] - 1] = 0
    c = 0
    max_num = 0
    min_num = 0
    for i in markers:
        if i:
            c += 1
            continue
        if c:
            max_num += c
            min_num += ((c + 1) >> 1)
        c = 0
    if c:
        max_num += c
        min_num += ((c + 1) >> 1)
    print(min_num, max_num)


def __starting_point():
    main()


__starting_point()

xx, kk = input().split(' ')
x=int(xx)
k=int(kk)
used = []
for i in range(5005): used.append(0)
used[x]=1
for i in range(k):
    p = [int (x) for x in input().split()]
    if p[0]==1 :
        used[p[1]]=used[p[2]]=1
    if(p[0]==2):
        used[p[1]]=1
mn, mx = 0, 0
for i in range(x):
    if(i==0): continue
    if(used[i]==1): 
        continue;
    j=i+1
    while(used[j]==0): 
        used[j]=1
        j=j+1
    mx+=j-i
    mn+=(j-i+1)//2
        


print (mn, mx)

x, k = map(int, input().split())
p = [1] * 4001
p[0] = p[x] = 0
for i in range(k):
    t = list(map(int, input().split()))
    if t[0] == 1: p[t[1]] = p[t[2]] = 0
    else: p[t[1]] = 0
s = a = b = 0
for i in p:
    if i: s += 1
    elif s:
        a += s
        b += (s + 1) // 2
        s = 0
print(str(b) + ' ' + str(a))

a=[int(i) for i in input().split(" ")]
present=a[0]
number=a[1]
l=[0 for i in range(present-1)]
while number:
    a=[int(i) for i in input().split(" ")]
    if(a[0]==2):
        l[a[1]-1]=2
    else:
        l[a[1]-1]=2
        l[a[2]-1]=1
    number-=1
maxi = l.count(0)
mini=0
c=l
for i in range(present-2):
    if c[i]==0 and c[i+1]==0:
        mini+=1
        c[i]=2
        c[i+1]=1
mini+=c.count(0)
print(mini,maxi)

#-------------------------------------------------------------------------------
# Name:        Codeforces
# Author:      Gogol
#-------------------------------------------------------------------------------

def main():
    x,k = list(map(int,input().split()));
    a = x * [0];
    t = k;
    ans1 = ans2 = 0;
    ans = 0;
    while (t > 0):
        c = list(map(int,input().split()))
        if (len(c) == 2):
            a[c[1]] = 1
        else:
            a[c[1]] = 1
            a[c[2]] = 1
        t = t - 1;
    t = 1
    while (t <= x - 1):
        if (a[t] != 1):
            ans2 = ans2 + 1;
        t = t + 1
    t = 1
    n = x - 1 - 1
    while (t <= n  and n > 2):
        if (a[t] == 0 and a[t+1] == 0):
            a[t] = 1;
            a[t+1] = 1
            ans1 = ans1 + 1;
            t = t + 2;
        else:
            t = t + 1
    t = 1
    while (t <= x - 1):
        if (a[t] == 0):
            ans1 = ans1 + 1;
        t = t + 1
    print(ans1,ans2)
def __starting_point():
    main()

__starting_point()

x, k = list(map(int, input().split()))
a = [0] * x
q = x - 1
for i in range(k):
	s = list(map(int, input().split()))
	a[s[1] - 1] = 1
	if len(s) == 3:
		a[s[2] - 1] = 1
	q-= len(s) - 1
p = 0
for i in range(x - 1):
	if a[i] == 0:
		p += 1
		if a[i + 1] == 0:
			a[i + 1] = 1
print(p, q)


#! /usr/bin/env python3.3

x, k=[int(s) for s in input().split()]
a=[0]
u=[False for i in range(4001)]
k=k+1
for i in range(1,k):
	o=[int(s) for s in input().split()]
	a.append(o[1])
	if o[0]==1: u[o[1]]=True

a.append(x);
k=k+1
a=sorted(a)
cnt1=cnt2=0
for i in range(1,k):
	if u[a[i-1]]: last=a[i-1]+1
	else: last=a[i-1]
	cnt1+=(a[i]-last)>>1
	cnt2+=a[i]-last-1

print(cnt1, cnt2)


#! /usr/bin/env python3.3

x, k=list(map(int, input().split()))
a=[0]
u=[False]*x
k=k+1
for i in range(1,k):
	o=list(map(int, input().split()))
	a.append(o[1])
	if o[0]==1: u[o[1]]=True

a.append(x);
k=k+1
a=sorted(a)
cnt1=cnt2=0
for i in range(1,k):
	if u[a[i-1]]: last=a[i-1]+1
	else: last=a[i-1]
	cnt1+=(a[i]-last)>>1
	cnt2+=a[i]-last-1

print(cnt1, cnt2)



#! /usr/bin/env python3.3

x, k=list(map(int, input().split()))
a=[False]*x
for i in range(k):
	o=list(map(int, input().split()))
	a[o[1]]=True
	if o[0]==1: a[o[2]]=True
cnt1=cnt2=d=0
for i in range(1,x):
	if a[i]:
		d=0
	else:
		d^=1
		cnt1+=d
		cnt2+=1
print(cnt1, cnt2)



from itertools import groupby
R = lambda: map(int, input().split())
x, k = R()
a = [0] * (x - 1)
for _ in range(k):
  l = list(R())
  if l[0] == 1:
    a[l[2] - 1] = 1
  a[l[1] - 1] = 1
b = [len(list(g)) for k, g in groupby(a) if k == 0]
x = y = 0
for l in b:
  x += l // 2 + l % 2
  y += l
print(x, y)

from itertools import groupby
R = lambda: map(int, input().split())
x, k = R()
a = [0] * (x - 1)
for _ in range(k):
  l = list(R())
  if l[0] == 1:
    a[l[2] - 1] = 1
  a[l[1] - 1] = 1
b = [len(list(g)) for k, g in groupby(a) if k == 0]
print(sum(l // 2 + l % 2 for l in b), sum(b))

curr, k=map(int, input().split())
done=[]
unused=[]

for i in range(k):
    op=list(map(int, input().split()))
    op.pop(0)
    for j in op:
        done.append(j)
    
i=1
while i<curr:
    if not i in done:
        unused.append(i)
    i+=1

i=0
res=0
while i<len(unused):
    if (i+1)<len(unused) and unused[i]+1==unused[i+1]:
        i+=2
    else:
        i+=1
    res+=1

print(res, end=' '); print(len(unused))

x, k = map(int, input().split())
r = [(x, x)]
for i in range(k):
    l = [int(x) for x in input().split()]
    r.append((l[1], l[2]) if l[0] == 1 else (l[1], l[1]))
r.sort()
v1, v2, prev = 0, 0, 0
for cr in r:
    v1 += (cr[0] - prev) // 2
    v2 += cr[0] - prev - 1
    prev = cr[1]
print(v1, v2)

x, k = [int(x) for x in input().split()]
used = [0, x]
for i in range(k):
	a, *l = [int(x) for x in input().split()]
	used += l
used.sort()
m = M = 0
for i in range(len(used) - 1):
	M += used[i + 1] - used[i] - 1
	m += (used[i + 1] - used[i]) // 2
print(m, M)


def main():
    x, k = map(int, input().split())
    l = [(0, 0)]
    for _ in range(k):
        tmp = list(map(int, input().split()))
        l.append((tmp[1], tmp[-1]))
        l.sort()
    l.append((x, x))
    mi = ma = 0
    for (a, b), (c, _) in zip(l, l[1:]):
        x = c - b
        mi += x // 2
        ma += x - 1
    print(mi, ma)


def __starting_point():
    main()
__starting_point()