## coding: UTF-8

N,K = map(int,input().split())
MOD = 998244353


able = [False] * (N+1)

for i in range(K):
    L, R = map(int,input().split())
    for j in range(L, R+1):
        able[j] = True

#print(able)

dp = ['a'] + [0] * (N)
dp[1] = 1
#print(dp)

for now in range(2, N+1):
    #print(now)
    point = 0
    for j in range(1, now):
        #print(now, j)
        if(able[j]):
            point += dp[now-j]
            point %= MOD
    dp[now] = point
#print(dp)
print(dp[-1])