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