# -*- coding: utf-8 -*-
"""
Created on Sat Sep 19 20:18:10 2020

@author: liang
"""
#D
N, K = map(int, input().split())
areas = list()
for i in range(K):
    l, r = map(int,input().split())
    areas.append((l,r))
areas_sum = [0] * N 

d = [0] * N
d[0] = 1
for i in range(N):
    for j in range(K):
        l, r = areas[j]
        if i-l >= 0:
            areas_sum[j] += d[i-l]
        if i-r-1 >= 0:
            areas_sum[j] -= d[i-r-1]
    d[i] += sum(areas_sum)
    d[i] %= 998244353 

#print(d)
ans = d[N-1]
print(ans)