N,K = map(int,input().split( ))
a = [0 for _ in range(N+1)]
for _ in range(K):
    L,R = map(int,input().split( ))
    for i in range(L,R+1):
        a[i] += 1
b = [0 for _ in range(N+1)]
b[0] = 1
for i in range(1,N+1):
    for j in range(1,i+1):
        b[i] += b[i-j]*a[j]
print(b[N-1])