import numpy as np
mod = 998244353

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

f = [-1] * n
f[0] = 1

def func(i):
    sum = 0
    for j in s:
        if j <= i:
            if (f[i-j] == -1):
                sum += func(i-j)
            else:
                sum += f[i-j]
            sum %= mod
    f[i] = sum
    return sum

print(func(n-1))