import sys
read = sys.stdin.read
#readlines = sys.stdin.readlines
import numpy as np
from numba import njit
def main():
    large_num = 998244353
    n, k = map(int, input().split())
    n -= 1
    dd = [0] * (n+1)

    m = map(int, read().split())
    ab = zip(m, m)
    for a, b in ab:
        for i1 in range(a, b + 1):
            dd[i1] = 1
    s = [i for i, v in enumerate(dd) if v == 1]
    s = np.array(s)

    @njit()
    def sol(s, n):
        dp = np.zeros(n+1)
        dp[0] = 1
        for i1 in range(1, n+1):
            for se in s:
                if se > i1:
                    break
                else:
                    dp[i1] += dp[i1 - se]
            dp[i1] = dp[i1] % large_num
        return dp[-1]
    print(int(sol(s, n)))

if __name__ == '__main__':
    main()
