import sys
read = sys.stdin.read
#readlines = sys.stdin.readlines
def main():
    large_num = 998244353
    n, k = map(int, input().split())
    n -= 1
    jump = set()
    m = map(int, read().split())
    ab = zip(m, m)
    for a, b in ab:
        jump.add((a, b))

    dp = [0] * (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(dp[-1])

if __name__ == '__main__':
    main()