from collections import defaultdict
from collections import deque
from collections import Counter
import math
import itertools

def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()

n,k = readInts()
pos = set()
for _ in range(k):
	l,r = readInts()
	for i in range(l,r+1):
		pos.add(i)

pos = sorted(list(pos))

dp = [-1]*(n+1)
dp[n]=1
ans = 0
for i in range(n-1,0,-1):
	t = 0
	for j in pos:
		if n-i>=j:
			t+=dp[i+j]
		else:
			break
	dp[i]=t%998244353

print(dp[1])