#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# FileName: 	D
# CreatedDate:  2020-09-19 20:49:34 +0900
# LastModified: 2020-09-19 21:53:27 +0900
#


import os
import sys
import numpy as np
# import pandas as pd


def main():
    unko = 998244353
    N, K = map(int, input().split())
    box = np.array([0])
    for _ in range(K):
        L, R = map(int, input().split())
        box = np.append(box, np.arange(L, R+1))
    box = sorted(box[1:])
    dp = [0]*(N+1)
    dp[1] = 1
    for i in range(1, N+1):
        if i + box[0] > N:
            break
        if dp[i] != 0:
            for b in box:
                if i + b > N:
                    break
                dp[i+b] += dp[i]
#        print(dp)
    print(dp[N]%unko)


if __name__ == "__main__":
    main()
