#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18;
const double pi = acos(-1);
const long long mod = 998244353;
vector<long long> dp(220000);
int main(void) {
  long long n, k;
  cin >> n >> k;
  vector<pair<long long, long long> > a(k);
  for (int i = 0; i < (k); ++i) {
    long long l, r;
    cin >> l >> r;
    r++;
    a[i] = {l, r};
  }
  dp[1] = 1;
  dp[2] = -1;
  for (int i = (1); i < (n + 1); ++i) {
    dp[i] += dp[i - 1];
    for (int j = 0; j < (k); ++j) {
      long long l, r;
      l = a[j].first;
      r = a[j].second;
      dp[i + l] += dp[i];
      dp[i + l] %= mod;
      dp[i + r] -= dp[i];
      dp[i + r] = (dp[i + r] + mod) % mod;
    }
  }
  cout << (dp[n] % mod + mod) % mod << endl;
  return 0;
}
