def countWays(arr, m, N): 
  
    count = [0 for i in range(N + 1)] 
 
    count[0] = 1

    for i in range(1, N + 1): 
        for j in range(m): 
            if (i >= arr[j]): 
                count[i] += count[i - arr[j]] 
 
    return count[N] 
    
n,k = map(int,input().split())

lol = set()

d = []

while k > 0:
    l,r = map(int,input().split())
    lol.add(l)
    lol.add(r)
    
    k -= 1
    
d = list(lol)
m = len(d)

print(countWays(d,m,n))