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

typedef long long int ll;
typedef vector<int> vi;
typedef set<int> si;
typedef set<ll> sll;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef long double ld;

#define pvec(v) for(auto e: v) cout << e << " ";
#define IO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define rep(i, a, b) for(int i = (a); i<(b); ++i)
#define pb push_back
#define INF 1000000005
#define MOD 1000000007
#define all(v) v.begin(), v.end()
#define mod 998244353

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

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

int main(){
	// IO
	int n, k;
	cin >> n >> k;
	vector<pii> ranges;
	int l, r;
	rep(i, 0, k) {
		cin >> l >> r;
		ranges.push_back({l, r});
	}	

	ll dp[n + 1] = {0LL};
	ll pref[n + 1] = {0LL};
	dp[1] = 1LL;
	pref[1] = 1LL;

	for(int i = 2; i <= n; ++i) {
		for(auto range: ranges) {
			if(range.first <= i) {
				int R = i - range.first, L = i - min(range.second, i);
				dp[i] = (dp[i]%mod + (pref[R] - pref[L - 1] + mod)%mod)%mod;
			}
		}
		pref[i] = (dp[i] +  pref[i - 1])%mod;
	}
	
	cout << dp[n] << endl;

	return 0;
}