// $%D%$.$%M%$.$%Y%$
// $%h%$:$%m%$:$%s%$

#pragma GCC optimize("O3")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define IOS ios::sync_with_stdio(false); cin.tie(0)
#define ll long long
#define ld long double
#define rep(i,a,n) for (int i=(int)(a);i<(int)(n);i++)
#define per(i,a,n) for (int i=(int)(n-1);i>=(int)(a);i--)
#define mp(a, b) make_pair(a, b)
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pil pair<int, ll>
#define pli pair<ll, int>
#define fi first
#define se second


const int MOD = 998244353; // = (119<<23)+1
const int MX = 2e5+5;
const ll INF = 1e18;
const ld PI = 4*atan((ld)1);
const int xd[4] = {1,0,-1,0}, yd[4] = {0,1,0,-1};




int main() {
    int n, k;
    cin >> n >> k;
    vector<int> dp(n + 1);
    dp[0] = 1;
    vector<int> pref(n + 1);
    pref[1] = 1;
    vector<pii> da(k);

    for (int i = 0; i < k; ++i) {
        cin >> da[i].first >> da[i].second;
    }
    for (int i = 1; i <= n; ++i) {
        for (auto x : da) {
            int l = i - x.second;
            int r = i - x.first + 1;
            dp[i] = (dp[i] + (pref[max(0, r)] - pref[max(0, l)] + MOD) % MOD) % MOD;
        }
        pref[i + 1] = (pref[i] + dp[i]) % MOD;
    }
    cout << dp[n - 1] << '\n';

}