#!/usr/bin/python3
#coding: utf-8

P = 998244353
N, K = (int(x) for x in input().split())
S = [[int(x) for x in input().split()] for _ in range(K)]
S.sort()

DP = [0] * (N+N+1)

DP[0] = 1
for now in range(N):
    for s in S:
        for i in range(s[0], s[1]+1):
            DP[now + i] += DP[now]
            DP[now + i] %= P
print(DP[N-1] % P)