### ----------------
### ここから
### ----------------

import sys
from io import StringIO
import unittest
#import itertools
#import heapq
#from collections import deque
#d = deque()

def yn(b):
    print("Yes" if b==1 else "No")
    return

def resolve():
    readline=sys.stdin.readline
    mod=998244353
    dp=[0]*(2*(10**5)+10)
    dp[0]=1
    n,k=map(int, readline().rstrip().split())
    #s=set()
    #lr=[0]*(2*(10**5)+10)
    ll=[0]*(2*(10**5)+10)
    rr=[0]*(2*(10**5)+10)
    for i in range(k):
        ll[i],rr[i]=map(int, readline().rstrip().split())
    for i in range(n-1):
        if dp[i] == 0:
            continue
        for j in range(k):
            for x in range(ll[j],rr[j]+1):
                if (i+x) > n:
                    break
                dp[i+x] += dp[i]
                dp[i+x]%=mod
    print(dp[n-1])
    #for i in range(n):
    #    if i > 0:
    #        lr[i]+=lr[i-1]
    #    if lr[i] > 0:
    #        s.add(i)

    #arr=list(map(int, readline().rstrip().split()))
    #n=int(readline())
    #ss=readline().rstrip()
    #yn(1)

    return

if 'doTest' not in globals():
    resolve()
    sys.exit()

### ----------------
### ここまで 
### ----------------