 //
#include<bits/stdc++.h>

using namespace std;

#define PB push_back
#define f first
#define s second
#define what_is(x) cerr << #x << " is " << x << endl;
#define int long long

typedef pair<ll, ll> pll;
typedef pair<int, int> pii;

const int INF = 1000000007;
const int MOD = 998244353;

int bit[200005];
int n, k;
void upd(int x, int val)
{
    for(; x <= n; x += x&-x)
    {
        bit[x] = (bit[x] + val) % MOD;
    }
}

int get(int x)
{
    int res = 0;
    for(; x>0; x -= x&-x)
    {
        res = (res + bit[x]) % MOD;
    }
    return res;
}
void solve_test()
{
    cin >> n >> k;
    upd(1, 1);
    vector<pii> v;
    for(int i=0; i<k; i++)
    {
        int l, r;
        cin >> l >> r;
        v.PB({l, r});
    }
    sort(v.begin(), v.end());
    for(int i=2; i<=n; i++)
    {
        int lo = 0, hi = 0;
        for(int j=0; j<k; j++)
        {
            lo = max(lo, v[j].f);
            hi = v[j].s;
            if(lo > hi)
                continue;
            if(lo >= i)
                break;
//            what_is(lo);
//            what_is(hi);
            hi = min(i-1, hi);
            int res = (MOD + get(i - lo) - get(i - hi - 1)) % MOD;
            upd(i, res);
            lo = hi+1;
        }
       //cout << i << " " << get(i) << "\n";
    }
    cout << get(n) - get(n-1) << "\n";

}

signed main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    int tests;
    tests = 1;
    //cin >> tests;
    while(tests--)
    {
        solve_test();
    }
    return 0;
}
