#include <bits/stdc++.h>
using namespace std;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
const long long oo = INT_MAX;
const long long MOD = 998244353;
const long long sz = 1e5 + 5;
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long tc = 1;
  while (tc--) {
    long long n, k;
    cin >> n >> k;
    vector<long long> poss;
    while (k--) {
      long long l, r;
      cin >> l >> r;
      for (long long i = l; i < r + 1; ++i) poss.push_back(i);
    }
    sort(poss.begin(), poss.end());
    vector<long long> dp(n + 1);
    dp[0] = 1;
    for (long long i = 1; i < n; ++i) {
      for (auto el : poss) {
        if (i - el < 0) break;
        dp[i] += dp[i - el];
        dp[i] %= MOD;
      }
    }
    cout << dp[n - 1] % MOD;
  }
}
