N, K = map(int, input().split())
P = 998244353
S = list(list(map(int, input().split())) for _ in range(K))

dp = [0]*(N+1)
tmp = 1
for i in range(1, N+1):
    tmp += dp[i]
    for s in S:
        l, r = s
        if i+l <= N:
            dp[i+l] += tmp
            dp[i+l] %= P
        if i+r+1 <= N:
            dp[i+r+1] -= tmp
            dp[i+r+1] %= P
print(dp[N])
