import sys
from collections import deque
sys.setrecursionlimit(10**7)

def skp(a):
    global ans
    if a == n:
        ans = ans+1
    elif a<n:
        for i in reach:
            skp(a+i)

reach = deque()

n,k = map(int,input().split())

for i in range(k):
    l,r =  map(int,input().split())
    for i in range(l,r+1,1):
        reach.append(i)
ans=0

skp(1)
print(ans)