/*
 * ----------------------------------------------------------------------------
 *  (: 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: Sun Sep 20 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};
    vector<pii> vec(k);
    for (int i = 0; i < k; i++)
        cin >> vec[i].F >> vec[i].S;
    ans[1] = 1;
    ans[2] = -1;
    for (int i = 1; i <= n; i++)
    {
        ans[i] += ans[i - 1] % mod;
        ans[i] %= mod;
        for (int j = 0; j < k; j++)
        {
            if (i + vec[j].F <= n)
            {
                ans[i] %= mod;
                ans[i + vec[j].F] += ans[i];
                ans[i + vec[j].F] %= mod;
            }
            if (i + vec[j].S < n)
            {
                ans[i + vec[j].S + 1] -= ans[i];
                ans[i + vec[j].S + 1] += mod;
                ans[i + vec[j].S + 1] %= mod;
            }
        }
    }

    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;
}

Measured memory_bytes: 5184