import sys
read = sys.stdin.read
#readlines = sys.stdin.readlines
import numpy as np
from numba import njit
def main():
    large_num = 998244353
    n, k = map(int, input().split())
    n -= 1
    jump = []
    m = map(int, read().split())

    for a, b in zip(m, m):
        jump.append((a, b))
    jump = np.array(jump)
    @njit()
    def sol(n, jump):

        dp = np.zeros(n+1)
        dp[0] = 1
        for i1 in range(1, n+1):
            for je in jump:
                for se in range(je[0],je[1]+1):
                    if se > i1:
                        break
                    else:
                        dp[i1] += dp[i1 - se]
            dp[i1] = dp[i1] % large_num
        return dp[-1]

    print(int(sol(n, jump)))

if __name__ == '__main__':
    main()
