import itertools
import math
import collections
def get_integral_value_combination(list, target):
    def a(idx, l, r, t):
        if t == sum(l): r.append(l)
        elif t < sum(l): return
        for u in range(idx, len(list)):
            a((u + 1), l + [list[u]], r, t)
        return r
    return a(0, [], [], target)

def get_unique_list(seq):
    seen = []
    return [x for x in seq if x not in seen and not seen.append(x)]
    
n, k = map(int, input().split())
s = []
for i in range(k):
  l, r = map(int, input().split())
  lr = [i for i in range(l, r + 1)]
  s += lr

s2 = []
for e in s:
  l = [e]
  m = ((n - 1) // e)
  l2 = l * m
  s2 += l2
ans = 0
ans_l = get_unique_list(get_integral_value_combination(s2, n - 1))

for e in ans_l:
  c = collections.Counter(e)
  p = math.factorial(len(e))
  for f in c:
    p = p // math.factorial(c[f])
  ans += p
ans = ans % 998244353
print(ans)