#include <bits/stdc++.h>
using namespace std;
signed main() {
  long long n, k;
  cin >> n >> k;
  vector<long long> l(k), r(k);
  set<long long> s;
  for (long long i = (0); i < (k); i++) {
    cin >> l[i] >> r[i];
    for (long long j = (l[i]); j < (r[i] + 1); j++) s.insert(j);
  }
  vector<long long> dp(n, 0);
  dp[0] = 1;
  for (long long i = (0); i < (n); i++) {
    for (auto itr = s.begin(); itr != s.end(); itr++) {
      if (i + *itr < n) dp[i + *itr] += dp[i];
      dp[i + *itr] %= 998244353;
      dp[i] %= 998244353;
    }
  }
  cout << dp[n - 1] << "\n";
}
