import numpy as np
from numba import njit

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

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)

    n_row = N//min(move) + 1

    dpt = np.array([[0] * N for i in range(n_row)], dtype="int64")
    dpt[0][0] = 1

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

    result = 0
    for i in range(n_row):
        result += dpt[i][-1]
    print(result%MOD)

if __name__ == '__main__':
    main()
