# -*- coding: utf-8 -*-

def input_int_array():
    return map(int, input().split())


def answer():
    n, k = input_int_array()
    spans = [tuple(input_int_array()) for x in range(k)]

    count = [0 for x in range(n)]
    count[0] = 1
    count[1] = -1

    for i in range(n):
        if i > 0:
            count[i] += count[i-1]
        for j in range(k):
            l, r = spans[j]
            r += 1
            if i + l < n:
                count[i + l] += count[i]
            if i + r < n:
                count[i + r] -= count[i]
    print(count[-1] % 998244353)


answer()
