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


#define ll long long int
#define ld long double
#define mod 998244353
#define big 1e18+100000000
#define small -big
#define pb push_back



template <typename T>

void prarr(T a)
{
     cerr << "[ ";
     
     for(auto i : a){
         cerr << i << " ";
     }
     
     cerr << "]" << endl;
}


#define trace(...) _er(#__VA_ARGS__, __VA_ARGS__)

template <typename Arg1>

void _er(const char* name, Arg1&& arg1){
	cerr << "[" << name << " : " << arg1 << "]" << endl;
}

template <typename Arg1, typename... Args>

void _er(const char* names, Arg1&& arg1, Args&&... args){
    
	const char* comma = strchr(names + 1, ',');
	cerr << "[" ; cerr.write(names, comma - names) << " : " << arg1 << "] ";
	_er(comma+2, args...);
}


const ll nax = (1LL << 20);

ll tree[nax + 1] = {0};
ll lazy[nax + 1] = {0};
ll arr[nax + 1] = {0};

ll n, k;

void add_self(ll & a, ll b) {
        a %= mod;
        b %= mod;
        a += b;
        a %= mod;
}

void add(ll curr, ll l, ll r, ll my_l, ll my_r, ll val) {
        
        if(l > n || l < 1 || r > n || r < 1 || l > r) {
                return;
        }
        
        
        add_self(tree[curr], lazy[curr]);
        if(l != r) {
                add_self(lazy[curr * 2], lazy[curr]);
                add_self(lazy[(curr * 2) + 1], lazy[curr]);
        }
        
        lazy[curr] = 0;
        
        if(l > my_r || r < my_l) {
                return;
        }
        
        if(l >= my_l && r <= my_r) {
                add_self(lazy[curr], val);
                return;
        }
        
        add(curr * 2, l , (l + r) / 2, my_l, my_r, val);
        add((curr * 2) + 1, ((l + r) / 2) + 1, r, my_l, my_r, val);
        
        
}
    

ll get(ll curr, ll l, ll r, ll ind) {
        
         
        if(l > n || l < 1 || r > n || r < 1 || l > r) {
                return 0;
        }
        
        add_self(tree[curr], lazy[curr]);
        if(l != r) {
                add_self(lazy[curr * 2], lazy[curr]);
                add_self(lazy[(curr * 2) + 1], lazy[curr]);
        }
        
        lazy[curr] = 0;
        
        if(l > ind || r < ind) {
                return 0;
        }
        
        if(l == r && l == ind) {
                return tree[curr];
        }
        
        ll sum = 0;
        
        add_self(sum, get(curr * 2, l, (l + r) / 2, ind));
        add_self(sum, get((curr * 2) + 1, ((l + r) / 2) + 1, r, ind));
        
        return sum;
        
        
}


void solve() {
        
        cin >> n >> k;
        
        pair<ll, ll> seg[k + 1];
        for(ll i = 1; i <= k; i++) {
                ll a, b;
                cin >> a >> b;
                seg[i] = {a, b};
        }
        
        add(1, 1, n, 1, 1, 1);
        
        for(ll i = 1; i <= n - 1; i++) {
                for(ll j = 1; j <= k; j++) {
                        ll a = seg[j].first;
                        ll b = seg[j].second;
                        ll c = get(1, 1, n, i);
                        add(1, 1, n, i + a, i + b, c);
                }
        }
        
        ll c = get(1, 1, n, n);
        cout << c << endl;
}




int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    

    int t=1;
   // cin >> t;

    for(int i = 1; i <= t; i++) {  
   
         solve();
    }


    return 0;
        
}


Measured memory_bytes: 11856