def N():
    return int(input())
def L():
    return list(map(int,input().split()))
def NL(n):
    return [list(map(int,input().split())) for i in range(n)]
mod = pow(10,9)+7
#import numpy
#import sympy
import math
md = 998244353

n,k = L()
lr = NL(k)
s = set()

for l,r in lr:
    s |= set(range(l,r+1))
l = [0]*(n+1)
l[1]=1

for i in range(1,n+1):
    for j in s:
        if i+j<n+1:
            l[i+j] = (l[i+j]+l[i])%md
    #print(l)
#print(l)
print(l[n]%md)