#!/usr/bin/env python3
def main():

    mod = 998244353
    n, k = map(int, input().split())

    lr = []
    for i in range(k):
        l, r = map(int, input().split())
        lr.append((l, r))

    kukan = []
    for w in lr:
        for i in range(w[0], w[1] + 1):
            kukan.append(i)

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

    dp[1] = 1
    for i in range(2, n + 1):
        for j in kukan:
            if i - j >= 0:
                dp[i] += dp[i - j] % mod

    print(dp[n] % mod)


main()

