# 配るDP、もらうDP



n, k = list(map(int, input().split()))

mod = 998244353



kukan = []

for _ in range(k):

    # 区間の問題は扱いやすいように[ )　の形に直せるなら直す

    l, r = list(map(int, input().split()))

    l -= 1

    kukan.append([l, r])



dp = [0 for i in range(n)]

dp[0] = 1



# 区間のL, Rは数字が大きいため、その差一つ一つを考えると時間がない！

# それゆえにL, Rの端を考えればいいようにするためにそこまでの累和を考える

ruiseki = [0 for i in range(n + 1)]

ruiseki[1] = 1

for i in range(1, n):

    for l, r in kukan:

        l = i - l

        r = i - r

        l, r = r, l

        # print(l, r)

        if r < 0:

            continue

        elif l >= 0:

            dp[i] += (ruiseki[r] - ruiseki[l]) % mod

        else:

            dp[i] += (ruiseki[r]) % mod

    ruiseki[i + 1] = (ruiseki[i] + dp[i])

    # print(ruiseki, dp)



print((dp[-1] % mod))

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

mod = 998244353



L = []

for _ in range(K):

    a, b = list(map(int, input().split()))

    b += 1

    L.append([a, b])



ruiwa = [0] * (N + 1)

dp = [0] * (N + 1)

dp[1] = 1

ruiwa[1] = 1

for i in range(2, N + 1):

    for l, r in L:

        l = i - l

        r = i - r

        l, r = r, l

        if r < 0:

            continue

        elif l >= 0:

            # print(ruiwa, r, l)

            dp[i] += (ruiwa[r] - ruiwa[l]) % mod

        else:

            dp[i] += ruiwa[r] % mod

    ruiwa[i] = (ruiwa[i - 1] + dp[i]) % mod



print((dp[-1] % mod))

# 配るDP、もらうDP
n, k = list(map(int, input().split()))
mod = 998244353
kukan = []
for _ in range(k):
    # 区間の問題は扱いやすいように[ )　の形に直せるなら直す
    l, r = list(map(int, input().split()))
    l -= 1
    kukan.append([l, r])
dp = [0 for i in range(n)]
dp[0] = 1
# 区間のL, Rは数字が大きいため、その差一つ一つを考えると時間がない！
# それゆえにL, Rの端を考えればいいようにするためにそこまでの累和を考える
ruiseki = [0 for i in range(n + 1)]
ruiseki[1] = 1
for i in range(1, n):
    for l, r in kukan:
        l = i - l
        r = i - r
        l, r = r, l
        # print(l, r)
        if r < 0:
            continue
        elif l >= 0:
            dp[i] += (ruiseki[r] - ruiseki[l]) % mod
        else:
            dp[i] += (ruiseki[r]) % mod
    ruiseki[i + 1] = ruiseki[i] + dp[i]
    # print(ruiseki, dp)
print((dp[-1] % mod))

N, K = list(map(int, input().split()))
mod = 998244353
L = []
for _ in range(K):
    a, b = list(map(int, input().split()))
    b += 1
    L.append([a, b])
ruiwa = [0] * (N + 1)
dp = [0] * (N + 1)
dp[1] = 1
ruiwa[1] = 1
for i in range(2, N + 1):
    for l, r in L:
        l = i - l
        r = i - r
        l, r = r, l
        if r < 0:
            continue
        elif l >= 0:
            # print(ruiwa, r, l)
            dp[i] += (ruiwa[r] - ruiwa[l]) % mod
        else:
            dp[i] += ruiwa[r] % mod
    ruiwa[i] = (ruiwa[i - 1] + dp[i]) % mod
print((dp[-1] % mod))

-# 配るDP、もらうDP -n, k = list(map(int, input().split())) +N, K = list(map(int, input().split())) -kukan = [] -for _ in range(k): -    # 区間の問題は扱いやすいように[ )　の形に直せるなら直す -    l, r = list(map(int, input().split())) -    l -= 1 -    kukan.append([l, r]) -dp = [0 for i in range(n)] -dp[0] = 1 -# 区間のL, Rは数字が大きいため、その差一つ一つを考えると時間がない！ -# それゆえにL, Rの端を考えればいいようにするためにそこまでの累和を考える -ruiseki = [0 for i in range(n + 1)] -ruiseki[1] = 1 -for i in range(1, n): -    for l, r in kukan: +L = [] +for _ in range(K): +    a, b = list(map(int, input().split())) +    b += 1 +    L.append([a, b]) +ruiwa = [0] * (N + 1) +dp = [0] * (N + 1) +dp[1] = 1 +ruiwa[1] = 1 +for i in range(2, N + 1): +    for l, r in L: -        # print(l, r) -            dp[i] += (ruiseki[r] - ruiseki[l]) % mod +            # print(ruiwa, r, l) +            dp[i] += (ruiwa[r] - ruiwa[l]) % mod -            dp[i] += (ruiseki[r]) % mod -    ruiseki[i + 1] = ruiseki[i] + dp[i] -    # print(ruiseki, dp) +            dp[i] += ruiwa[r] % mod +    ruiwa[i] = (ruiwa[i - 1] + dp[i]) % mod