#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <chrono>
#define pb push_back
#define INF 0x3f3f3f3f
#define LINF 0x3f3f3f3f3f3f3f3f
#define endl '\n'
#define ll long long
#define f first
#define fin cin
#define fout cout
#define int long long
#define s second
#define FAST cin.tie(0), cout.tie(0), ios::sync_with_stdio(0)
#define debug(x) cout << "DEBUG " << x << endl
#define debug2(x, y) cout << "DEBUG " << x << " " << y << endl
#define debug3(x, y, z) cout << "DEBUG " << x << " " << y << " " << z<< endl
#define debug4(x, y, z, o) cout << "DEBUG " << x << " " << y << " " << z<< " " << o << endl
#define all(x) x.begin(), x.end()
#define left vadia
#define lb lower_bound
#define right puta
using namespace std;
using namespace __gnu_pbds;
void setIO(string s) {
  ios_base::sync_with_stdio(0); cin.tie(0); 
  freopen((s+".in").c_str(),"r",stdin);
  freopen((s+".out").c_str(),"w",stdout);
}
typedef pair<ll, ll> pii;
typedef vector<vector<char>> mat;
typedef pair<int, string> pis;
const ll mod = 998244353;
const int MAXN = 2e5 + 5;
const int MAXV = 1e6+5;
typedef vector<int> vi;
typedef pair<int, pair<int, int>> piii;

int bit[MAXN], n;

void update(int x, int k) {
	if(x > n)
		return;
    while(x <= n) {
        bit[x] = (bit[x] + k)%mod;
        x += (x & -x);
    }
}

int query(int x) {
    int s = 0;
    while(x > 0) {
        s = (s + bit[x])%mod;
        x -= (x & -x);
    }
    return s%mod;
}

int32_t main() {
	
	int k;
	cin >> n >> k;

	vector<pii> seg(k);
	for(pii &i : seg)
		cin >> i.f >> i.s;

	update(1, 1);
	update(2, -1);

	for(int i = 1; i <= n; i++)
		for(int j = 0; j < k; j++) {
			
			int l = seg[j].f, r = seg[j].s;
			update(i+l, query(i));
			update(i+r+1, -query(i));

		}

	cout << query(n) << endl;

}
