import numpy as np
N,K = [int(a) for a in input().split()]
LR = []
for _ in range(K):
    L,R = [int(a) for a in input().split()]
    LR.append([L,R])
dp = [0]*N
dp[0] = 1
f = 998244353
for i in range(1,N):
    for j in range(len(LR)):
        if i-LR[j][1] >= 0:
            dp[i] += sum(dp[i-LR[j][1]:i-LR[j][0]+1]) %f
        elif i-LR[j][0] >= 0: 
            dp[i] += sum(dp[:i-LR[j][0]+1]) %f
print(int(dp[-1]))