def paths(n,ways,c,s):
    if s==n:
        c[0]+=1
        return
    for i in range(len(ways)):
        midpath=s+ways[i]
        if midpath<=n:
            paths(n,ways,c,midpath)
            



n,k=map(int,input().split())
s=set()
for i in range(k):
    a,b=map(int,input().split())
    for i in range(a,b+1):
        s.add(i)
c=[0]
source=1
(paths(n,list(s),c,source))
print(c[0])