n, k =  map(int, input().split())

strides = set()
c = [0] * (n + 1)
c[1] = 1

for i in range(k):
  a, b = map(int, input().split())
  strides.add(a)
  strides.add(b)
  
for i in range(1, n + 1):
  for stride in strides:
    try:
      c[i + stride] += c[i]
    except:
      pass

print(c[-1] % 998244353)