#include <bits/stdc++.h>
using namespace std;
const int inf = INT_MAX;
const int MAX = 510000;
const long long MOD = 998244353;
int main() {
  long long n, k;
  cin >> n >> k;
  set<long long> s;
  for (long long i = (0); i < (k); ++i) {
    long long l, r;
    cin >> l >> r;
    for (long long i = (l); i < (r + 1); ++i) {
      s.insert(i);
    }
  }
  vector<long long> dp(n, 0);
  dp[0] = 1;
  for (long long i = (1); i < (n); ++i) {
    for (auto u : s) {
      if (i - u >= 0) {
        dp[i] += dp[i - u];
        dp[i] %= MOD;
      }
    }
  }
  cout << (dp[n - 1] % MOD) << endl;
  ;
}
