n,k = map(int,input().split())
p = 998244353
dx = [0]*n
for i in range(k):
    l,r = map(int,input().split())
    for j in range(l-1,r):
        dx[j] = 1

dp = [0]*n
dp[0]=1
for i in range(1,n):
    for j in range(i+1):
        if dx[j]==1:
            dp[i] += dp[i-(j+1)]%p
            #print(dp)
    else:
        dp[i]=dp[i]%p
print(dp[n-1])
