
// Problem : D - Leaping Tak
// Contest : AtCoder - AtCoder Beginner Contest 179
// URL : https://atcoder.jp/contests/abc179/tasks/abc179_d
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define int long long
#define db double
#define mod 998244353
#define pb push_back
#define pp pair<int,int>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repe(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=b;i>=a;i--)
#define maxn 200005
#define ss second
#define ff first
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub upper_bound
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
int inv(int a, int b){
 return 1<a ? b - inv(b%a,a)*b/a : 1;
}
int dp[maxn],n,k;
void update(int idx,int val){
	for(int i=idx;i<=n;i+=(i&-i))
	{
		dp[i] += val;
		dp[i] %= mod;
	}
}
int query(int idx)
{
	int sum = 0;
	for(int i=idx;i>0;i-=(i&-i))
	{
		sum += dp[i];
		sum %= mod;
	}
	return sum;
}
void solve()
{
	cin >> n >> k;
	vector<pp> v(k);
	for(int i=0;i<k;i++)
	{
		int x,y;
		cin >> x >>  y;
		v[i] = {x,y};
	}
	sort(all(v));
	update(1,1);
	for(int i=2;i<=n;i++)
	{
		int ans = 0;
		for(int j=0;j<k;j++)
		{
			int l = v[j].ff,r=v[j].ss;
			int x = i-l;
			if(x <= 0)
				break;
			int y = max((int)1,i-r);
			y--;
			int tmp = query(x);
			tmp -= query(y);a
			tmp += mod;
			tmp %= mod;
			ans += tmp;
			ans %= mod;
		}
		update(i,ans);
		if(i== n)
		{
			cout << ans ;
			return;
		}
	}
}
signed main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t=1;
    //cin >> t;
    while(t--)
    solve();
    return 0;
}
