#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 998244353;
int main() {
  ll n, k;
  cin >> n >> k;
  vector<int> l(k), r(k);
  for (int i = 0; i < (int)(k); ++i) {
    cin >> l[i] >> r[i];
  }
  vector<int> dp(n + 10);
  dp[1] = 1;
  for (int i = 1; i < n; i++) {
    dp[i] += dp[i - 1];
    dp[i] %= mod;
    for (int j = 0; j < (int)(k); ++j) {
      int num = min(i + r[j] + 1, (int)(n + 1));
      dp[i + l[j]] += dp[i];
      dp[i + l[j]] %= mod;
      dp[num] -= dp[i];
      if (dp[num] < 0) dp[num] += mod;
    }
  }
  dp[n] %= mod;
  cout << dp[n] << endl;
  return 0;
}
