#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)n; i++)
using ll = long long;
const ll mod = 998244353;

int main(){
  ll n, k;
  cin >> n >> k;
  ll l[k], r[k];
  rep(i,k) cin >> l[i] >> r[i];
  vector<ll> dp(n), sum(n);
  dp[0] = 1, sum[0] = 1;
  for(int i = 1; i < n; i++) {
    rep(j,k) {
      if(i-l[j] >= 0) (dp[i] += sum[i-l[j]]) %= mod;
      if(i-r[j]-1 >= 0) (dp[i] -= sum[i-r[j]-1]) %= mod;
    }
    sum[i] = (sum[i-1] + dp[i]) % mod;
  }
  if(dp[n-1] < 0) dp[n-1] += mod;
  cout << dp[n-1] << endl;
  return 0;
}
