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


#for i in range(k):
#    a,b = map(int,input().split())
#    for i in range(a,b+1):
#        s += [i]

s = [[int(i) for i in input().split()] for _ in range(k)]

#print(s)
#s = list(set(s))
len_s = len(s)

ans = [0] * (n+1)
ans[1] = 1

for i in range(2,n+1):
    for j in range(k):
        ans[i] += sum(ans[max(0,i-s[j][1]):max(0,i-s[j][0]+1)])
        #print(i,sum(ans[max(0,i-s[j][0]):max(0,i-s[j][1]+1)]),max(0,i-s[j][0]),max(0,i-s[j][1]+1))

#print(ans)

print(ans[n]%998244353)
