P = 998244353

N, K = [int(x) for x in input().split()]
intervals = []
for _ in range(K):
    L, R = [int(x) for x in input().split()]
    intervals.append([L, R])

dp = [0]*(N + 1)
csum = [0]*(N + 1)
dp[1] = 1
csum[1] = 1
for i in range(2, N + 1):
    for j in range(K):
        L, R = intervals[j]
        dp[i] = (dp[i] +  csum[max(0, i - L)] - csum[max(0, i - R - 1)]) % P
    csum[i] = (csum[i - 1] + dp[i]) % P

ans = dp[N]
print(ans)