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
    m = map(int, read().split())
    ma = np.zeros(k)
    mb = np.zeros(k)
    cnt = 0
    for a, b in zip(m, m):
        ma[cnt] = a
        mb[cnt] = b
        cnt += 1

    @njit()
    def sol(n, ma, mb):
        dd = np.zeros(n+1)
        for a, b in zip(ma, mb):
            for i1 in range(a, b+1):
                dd[i1] = 1
        s = [i for i, v in enumerate(dd) if v == 1]
        s = np.array(s)
        dp = np.zeros(n+1)
        dp[0] = 1
        for i1 in range(1, n+1):
            for se in s:
                if se > i1:
                    break
                else:
                    dp[i1] += dp[i1 - se]
            dp[i1] = dp[i1] % large_num
        return dp[-1]

    print(int(sol(n, ma, mb)))

if __name__ == '__main__':
    main()

