#include <bits/stdc++.h>
#define l_ength size
const int inf = (1<<30);
const int mod = 998244353;
using ll = long long;
using namespace std;

ll dp[200100];
ll sum[200100];
vector<pair<int, int>> vspan;

int main(){
	int n, k; cin >> n >> k;
	for( int i = 0; i < k; ++i ){
		int x, y; cin >> x >> y;
		vspan.emplace_back(x, y);
	}
	dp[0] = 1;
	sum[1] = 1;
	for( int i = 0; i < n; ++i ){
		for( int s = 0; s < k; ++s ){
			int l = vspan[s].first;
			int r = vspan[s].second;
			dp[i+1] += ( mod + sum[max(0, i+2-l)]-sum[max(0, i+2-r-1)] );
			dp[i+1] %= mod;
		}
		sum[i+2] = sum[i+1] + dp[i+1];
		sum[i+2] %= mod;
	}
	cout << dp[n-1] % mod << endl;
}