import numpy as np
from numba import njit

@njit
def solve(dpt, N, move, MOD):
    for i in range(N):
        for m in move:
            if i + m < N:
                dpt[i+m] = dpt[i] + dpt[i+m]
                dpt[i+m] %= MOD
    return dpt[N-1]

def main():
    MOD = 998244353

    N, K = map(int, input().split())
    move = []
    for i in range(K):
        l, r = map(int, input().split())
        move.extend(list(range(l, r+1)))
    move = np.array(move)
    dpt = np.zeros(N, dtype='int64')
    dpt[0] = 1

    print(solve(dpt, N, move, MOD))


if __name__ == '__main__':
    main()
