def main():
    n,k = map(int,input().split())
    rngs = []
    for i in range(k):
        rngs.append(list(map(int,input().split())))
    print(solve(n,k,rngs))


def solve(n,k,rngs):
    mod = 998244353
    imos = [0] * (n+2)
    dp = [0] * (n+1)
    dp[1] = 1
    temp = 1

    for i in range(1,n+1):
        #print("i:",i,"temp:",temp)
        dp[i] = temp
        temp += imos[i]



        for rng in rngs:
                start,end = rng
                start += i
                try:
                    imos[start] += 1
                except IndexError:
                    continue
                try:
                    imos[end+1] -= 1
                except IndexError:
                    continue
    #print(dp)
    #print(imos)
    return dp[n]%mod



if __name__ == '__main__':
    main()
