#coding:utf-8

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

T = [0] * (N+1)

for i in range(K):
    l,r = map(int,input().split())
    for j in range(l,r+1):
        T[j] = 1

S = []

for i in range(N+1):
    if T[i] == 1:
        S.append(i)

dp = [0] * N

for i in range(N):
    for s in S:
        if s == i:
            dp[i] += 1
        if s <= i:
            dp[i] += dp[i-s]
            dp[i] = dp[i] % 998244353

print("{}".format(dp[N-1]))