#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int L[12],R[12];
const int MAX_N = 200005;
const ll MOD = 998244353;
ll dp[MAX_N],sum[MAX_N];

int main()
{
	int N,K;
	cin >> N >> K;
	rep(i,K)
	{
		cin >> L[i] >> R[i];
	}
	dp[1] = 1;
	sum[1] = 1;
	for (int i = 2; i <= N; ++i)
	{
		rep(j,K)
		{
			int l = max(1,i-R[j]), r = max(0,i-L[j]);
			ll temp = (sum[r] - sum[l-1]+ MOD) % MOD;
			dp[i] = (dp[i] + temp) % MOD;
		}
		sum[i] = (sum[i-1] + dp[i]) % MOD;
	}
	cout << dp[N] << endl;
	return 0;
}