n,k = map(int,input().split())
lis = [list(map(int,input().split())) for i in range(k)]
imos = [0] * (2 * n + 1)
imos[0] = 1
imos[1] = -1
ans = [1]
  # print(imos)
for i in range(n):
    for x,y in lis:
        imos[i+x] += ans[-1]
        imos[i+y+1] -= ans[-1]
    ans.append((ans[-1]+imos[i+1])%998244353)
  #print(imos)
print(ans[-2])