n, k = map(int,input().split())
l_r = [ list(map(int, input().split())) for _ in range(k)  ]
s_s_l = [  list(range(l,r+1)) for l,r in l_r ]
d = [0] * n
d[0] = 1
for i in range(1, n):
    c = 0
    for s_l in s_s_l:
        for s in s_l:
            if s <= i:
                if d[i-s] > 0:
                    c += d[i-s]
            else:
                break
    d[i] = c%998244353
print(d[-1]%998244353)