#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll M = 998244353;
int si[] = {-1, 0, 1, 0};
int sj[] = {0, -1, 0, 1};
int main() {
  ll n, k;
  cin >> n >> k;
  vector<ll> l(k), r(k);
  vector<ll> s;
  for (int i = 0; i < (int)(k); i++) {
    cin >> l[i] >> r[i];
    for (int j = 0; j < (int)(r[i] - l[i] + 1); j++) s.push_back(l[i] + j);
  }
  vector<ll> dp(n + 1, 0);
  dp[1] = 1;
  for (int i = 1; i <= n; i++) {
    auto itr = s.begin();
    for (int j = 0; j < (int)(s.size()); j++) {
      if (i - *itr > 0) dp[i] += dp[i - *itr];
      dp[i] %= M;
      itr++;
    }
  }
  cout << dp[n] % M << endl;
  return 0;
}
