/*
 * ----------------------------------------------------------------------------
 *  (: Bismillahir Rahmanir Rahim :) 
 * File: /home/grimfirefly/Programming/Atcoder/Today/D_Leaping_Tak.cpp
 * Project: /home/grimfirefly/Programming/Atcoder/Today
 * Created Date: Saturday, September 19th 2020, 6:57:54 pm
 * Author: Grim Firefly :)
 * Author Mail : GrimFirefly1@gmail.com
 * -----
 * Last Modified: Sat Sep 19 2020
 * Modified By: Grim Firefly :)
 * -----
 *   ________        .__           ___________.__                  _____ .__          
 *  /  _____/_______ |__|  _____   \_   _____/|__|_______   ____ _/ ____\|  |  ___.__.
 * /   \  ___\_  __ \|  | /     \   |    __)  |  |\_  __ \_/ __ \\   __\ |  | <   |  |
 * \    \_\  \|  | \/|  ||  Y Y  \  |     \   |  | |  | \/\  ___/ |  |   |  |__\___  |
 *  \______  /|__|   |__||__|_|  /  \___  /   |__| |__|    \___  >|__|   |____// ____|
 *         \/                  \/       \/                     \/              \/     
 * 
 *           |\_|\
 *           | a_a\
 *           | | "]
 *       ____| '-\___
 *      /.----.___.-'\
 *     //        _    \
 *    //   .-. (GF)  /|
 *   |'|  /\:  .--  / \
 *  // |-/  \_/____/\/~|
 * |/  \ |  []_|_|_] \ |
 * | \  | \ |___   _\ ]_}
 * | |  '-' /   '.'  |
 * | |     /    /|:  | 
 * | |     |   / |:  /\
 * | |     /  /  |  /  \
 * | |    |  /  /  |    \
 * \ |    |/\/  |/|/\    \
 *  \|\ |\|  |  | / /\/\__\
 *   \ \| | /   | |__
 *        / |   |____)
 *        |_/
 * ----------------------------------------------------------------------------
 */

//Code Start
#include <bits/stdc++.h>
using namespace std;

//constant
#define PI acos(-1.0)
#define SZ 10000
#define mod 998244353
//typedef
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef double db;
typedef unsigned un;
typedef pair<int, int> pii;
typedef vector<int> vi;

//Debug Setting up
#define watch(x) cout << (#x) << "=" << x << endl
#define watch2(x, y) cout << (#x) << "=" << x << " & " << (#y) << "=" << y << endl;
#define watchara(wow)     \
    for (auto x : wow)    \
    {                     \
        cout << x << " "; \
    }                     \
    cout << "\n"

//defining fast_io
#define fast_io                       \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL)

//defining something
#define F first
#define S second

//Main Function Start From Here
void solve()
{
    ll n;
    int k;
    cin >> n >> k;
    ll ans[n + 1] = {0};
    int d[n + 2] = {0};
    int l, r;
    for (int i = 0; i < k; i++)
    {
        cin >> l >> r;
        d[l]++;
        d[r + 1]--;
    }
    set<int> ST;
    for (int i = 1; i < n + 2; i++)
    {
        d[i] += d[i - 1];
        if (d[i] > 0)
        {
            ST.insert(i);
        }
    }
    ans[1] = 1;
    for (int i = 1; i <= n; i++)
    {
        if (ans[i] > 0)
            for (auto it = ST.begin(); it != ST.end(); it++)
            {
                if (i + *it <= n)
                {
                    ans[i] %= mod;
                    ans[i + *it] += ans[i];
                    ans[i + *it] %= mod;
                }
                else
                {
                    break;
                }
            }
    }
    cout << ans[n] << endl;
    // for (auto i = ST.begin(); i != ST.end(); i++)
    // {
    // cout << *i << " ";
    // }
}

int main()
{
    fast_io;
    // set<int> ST;
    // ST.insert(1);
    // ST.insert(2);
    // ST.insert(3);

    solve();

    return 0;
}