# 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())
    leaps.append((l, r))
mod = 998244353
dp = [0] * (n + 1)
dp[1] = 1

for i in range(2, n + 1):
    for l, r in leaps:
        li = i - l
        ri = i - r
        dp[i] += dp[max(li, 0)] - dp[max(ri - 1, 0)]
        dp[i] %= mod


print(dp[n] % mod)
