n,k = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(k)]

ab.sort()

dp=[0]*(n)
dp[0] =1

for i in range(1,n):
    res = 0
    for j in ab:
        if j[0] > i:
            break
        elif j[1] >i:
            res += sum(dp[0:(i-j[0])+1])
        else:
            res += sum(dp[(i-j[1]):(i-j[0])+1])
    dp[i] = (dp[i] +res) % 998244353 

print(dp[n-1]%998244353 )