import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n,k,*data = list(map(int,read().split()))
mod = 998244353

dp = [0] * n
dp[0] = 1
route = 0
for j in range(1,n):
    for i in range(k):
        l,r = data[i*2:i*2+2]
        if(j >= l):
            route += dp[j-l]
        if(j > r):
            route -= dp[j-r-1]
        route %= mod
    dp[j] += route


print(dp[-1])