n,k = map(int,input().split())
s = []
ans = 0

for i in range(k):
    L,R = map(int,input().split())
    
    for j in range(L,R+1):
        s.append(j)
    
s = sorted(set(s))

import collections
q = collections.deque()

q.append(1)
    
while q:
    now = q.popleft()
        
    for i in s:
        if now + i < n:
            q.append(now+i)
        elif now + i == n:
            ans += 1
            break
        else:
            break
            
    ans %= 998244353
            
print(ans)