f = open('26_29234.txt')
K = int(f.readline())
N = int(f.readline())
zayavki = []
for s in f:
start, end = map(int, s.split())
zayavki.append([start, end])
zayavki.sort()
comp_free = [0] * K
comp_profit = [0] * K
served = 0
for start, end in zayavki:
for i in range(K):
if comp_free[i] <= start:
comp_free[i] = end
served += 1
duration = end - start
comp_profit[i] += duration * (duration + 1) // 2
break
print(served, max(comp_profit))