# https://atcoder.jp/contests/abc179/tasks/abc179_d

n, k = map(int, input().split())
leaps = []
for _ in range(k):
    l, r = map(int, input().split())
    for i in range(l, r+1):
        leaps.append(i)

dp = [0] * (n + 1)
dp[1] = 1

for i in range(1, n + 1):
    for leap in leaps:
        if(i - leap >= 0):
            dp[i] += dp[i - leap]


print(dp[n] % 998244353)
