#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
  int N, K;
  cin >> N >> K;
  vector<ll> dp(N, 0);
  dp.at(0) = 1;
  vector<int> S;
  int x, y;
  const int mod = 998244353;
  for (int i = 0; i < (K); ++i) {
    cin >> x >> y;
    for (int i = x; i <= y; i++) S.push_back(i);
  }
  sort(S.begin(), S.end());
  for (int i = 0; i < (N); ++i) {
    for (auto e : S) {
      if (i + e < N) {
        dp.at(i + e) += dp.at(i);
        dp.at(i + e) %= mod;
      } else
        break;
    }
  }
  cout << dp.at(N - 1) << endl;
  return 0;
}
