import sys
read = sys.stdin.read
#readlines = sys.stdin.readlines
import numpy as np
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))
    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
    print(int(dp[-1]))

if __name__ == '__main__':
    main()
