n, k  = map(int, input().split())
lis = []
ans = [0]*n + [1]
anssum = [0]*(n) + [1] + [0]*2*n
for _ in range(k):
  a, b = map(int,input().split())
  lis.append((a, b))
for k in reversed(range(1, n)):
  for a, b in lis:
    ans[k] = ans[k] - anssum[k+b+1] + anssum[k+a]
  anssum[k] = anssum[k+1] + ans[k]
print(ans[1]%998244353)