mod = 998244353
n,k = map(int,input().split())
c = [0 for _ in range(n+1)]
cs = [0 for _ in range(n+1)]
c[1] = 1
cs[1] = 1
csi = 1
lr = [(0,0) for _ in range(k)]
for i in range(k):
  li,ri = map(int,input().split())
  lr[i] = (li,ri)
for i in range(2,n+1):
  for lri in lr:
    l,r = lri
    if i-l > 0:
      c[i] = (c[i]+cs[i-l]-cs[max(0,i-r-1)])%mod
  csi = (c[i]+csi)%mod
  cs[i] = csi
print(c[n])