N,Q = map(int, input().split())
a = [list(map(int, input().split())) for i in range(Q)]
cnt = [0]*N
cnt[0]=1
for i in range(0,N-1):
  for j in range(Q):
    for k in range(a[j][0],a[j][1]+1):
      if i+1+k<=N:
        cnt[i+k]=(cnt[i+k]+cnt[i])%998244353
print(cnt[N-1])