#include <iostream>
#include <vector>
#include <string>
#include <bits/stdc++.h>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <deque>
#include <tuple>
#include <unordered_set>
#include <array>
#include <string>

using namespace std;
#define ll long long
#define ar array
const ll mod=998244353;

int main() {
	ll n, k;
	cin >> n >> k;
	ll s[k][2];
	for (int i=0; i<k; i++) {
		cin >> s[i][0] >> s[i][1];
	}
	vector<ll> p(n+1, 0);
	p[1]=1LL;
	for (ll i=2; i<=n; i++) {
		p[i]+=p[i-1];
		p%=mod;
		for (ll j=0; j<k; j++) {
			ll x=s[j][0], y=s[j][1];
			if (i-x>=1) p[i]+=p[i-x]-p[i-min(y, i-1)-1];
			p[i]%=mod;
		}
		p[i]%=mod;
	}
	cout << (p[n]-p[n-1]+mod)%mod;
	return 0;
}