import numpy as np
# import math
# import copy
# from collections import deque
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(10000)
from numba import njit,i8


@njit(i8(i8,i8,i8[:,:],i8,i8[:],i8,i8,i8,i8))
def give_cnt(N,K,LR,mod,dp,L,R,l,r):
    for i in range(N):
        for k in range(K):
            l = LR[k][0]
            r = LR[k][1]
            if i + l >= N:
                continue
            else:
                L = i + l
            if i + r >= N:
                R = N - 1
            else:
                R = i + r
            dp[L:R+1] += dp[i]
            dp[L:R+1] %= mod
    return dp[-1]


def main():
    N,K = map(int,input().split())
    LR = [list(map(int,input().split())) for i in range(K)]
    LR = np.array(LR)

    mod = 998244353

    dp = [0 for i in range(N)]
    dp[0] = 1
    dp = np.array(dp)

    res = give_cnt(N,K,LR,mod,dp,0,0,0,0)

    # print(dp)
    print(res)



main()
