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

#define IOS ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define AfterDecimal(n) cout << fixed << setprecision(n);
#define ll long long int
#define ld long double
#define all(a) a.begin(), a.end()
#define pii pair<int, int>
#define pll pair<ll, ll>
#define bits(x) __builtin_popcount(x)

using namespace __gnu_pbds;
using namespace std;

// #pragma GCC optimize("Ofast")
// #pragma GCC target("avx,avx2,fma")
// #pragma GCC optimization ("unroll-loops")

//template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

typedef tree<int, null_type, less<int>, rb_tree_tag,
            tree_order_statistics_node_update>
    ordered_set;

#ifdef LOCAL
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
template<typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cout << "# "<< name << " = " << arg1 << '\n';
}
template<typename Arg1, typename... Args>
void __f(const char* names, Arg1 && arg1, Args &&... args){
        const char* comma = strchr(names + 1 ,',');
        cout << "# ";
        cout.write(names, comma - names)<< " = " << arg1 << " | ";
        __f(comma + 1, args...);
}
#else
#define debug(...) 36
#endif


std::mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
inline int ri(int a, int b) {
    return uniform_int_distribution<int>(a, b)(rng);
}

ll power(ll x, ll y, ll p){
   ll res = 1;
   x = x % p;
   while (y > 0) {
      if (y & 1)
         res = (res * x) % p;
      y = y >> 1;
      x = (x * x) % p;
   }
   return res;
}

const ll INF = (ll)(8e18);
const ll MOD = (ll)(1e9 + 7);
const ll HMOD = (ll)4222234727;
const ll Hashprime = (ll)31;
const ll mod = (ll)(998244353);

const int maxn = 200100;

// Segment tree and Lazy propagation

ll segment[4 * maxn], lazy[4 * maxn];

void propagate(ll node){
    lazy[node + node] += lazy[node];
    lazy[node + node + 1] += lazy[node];
    lazy[node] = 0;
    return;
}

void Update(ll node){
   segment[node] = (segment[node + node] + lazy[node + node] +
                          segment[node + node + 1] + lazy[node + node + 1]);
   segment[node] %= mod;
    return;
}

void updateLazy(ll l, ll r, ll start, ll end, ll val, ll node){
    if(r < start || l > end) return;
    if(start <= l && end >= r){
        lazy[node] += val;
        return;
    }
    propagate(node);
    ll mid = (l + r) >> 1;
    updateLazy(l, mid, start, end, val, node + node);
    updateLazy(mid + 1, r, start, end, val, node + node + 1);
    Update(node);
}

ll queryLazy(ll l, ll r, ll start, ll end, ll node){
    if(r < start || l > end){
        return 0LL;
    }
    if(start <= l && end >= r) return segment[node] + lazy[node];
    propagate(node);
    ll mid = (l + r) >> 1;
    ll left = queryLazy(l , mid, start, end, node + node);
    ll right  = queryLazy(mid + 1, r, start, end, node + node + 1);
    Update(node);
    return (left + right) % mod;
}

int32_t main(){
    IOS;
    #ifndef ONLINE_JUDGE
    //  freopen("input.txt", "r", stdin);
    //  freopen("output.txt", "w", stdout);
    #endif
    int t = 1; // cin >> t;
    while(t--){
       ll n,k; cin >> n >> k;
       std::vector<pll> v;
       for(ll i = 1; i <= k; i++){
          ll l,r; cin >> l >> r;
          v.push_back({l, r});
       }
       updateLazy(1, n, 1, 1, 1, 1);
       for(ll i = 1; i <= n; i++){
          for(pll j : v){
             ll val = queryLazy(1, n, i, i, 1);
             if((i + j.first) <= n) updateLazy(1, n, i + j.first, min(i + j.second, n), val, 1);
          }
       }
       cout << queryLazy(1, n, n, n, 1) << '\n';
    }
    #ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
    #endif
}
//g++ -DLOCAL -std=c++17 -Wshadow -Wall -o "c" "comp.cpp" -fsanitize=address -fsanitize=undefined -D_GLIBCXX_DEBUG -g


Measured memory_bytes: 9808