def sum(i):
    if nums[i] != -1:
        return nums[i]

    else:
        nums[i] = 0
        for k in S:
            if i - k > 0:
                nums[i] += sum(i - k)
            else:
                break
        return nums[i]


S = set()
temp = []
temp = list(map(int, input().split()))
N = temp[0]
K = temp[1]
nums = [-1, 1]

for i in range(2, N + 1):
    nums.append(-1)

for i in range(0, K):
    temp = list(map(int, input().split()))
    L = temp[0]
    R = temp[1]

    for k in range(L, R + 1):
        S.add(k)

print(sum(N) % 998244353)
