#include <bits/stdc++.h>
using namespace std;
const long long mod = 998244353;
int main() {
  cin.tie(0)->sync_with_stdio(0), cin.exceptions(cin.failbit);
  long long n, k;
  cin >> n >> k;
  vector<long long> nw;
  map<int, bool> used;
  for (int i = 0; i < k; ++i) {
    long long x, y;
    cin >> x >> y;
    for (int j = x; j <= y; ++j)
      if (!used[j]) nw.emplace_back(j), used[j] = true;
  }
  sort(begin(nw), end(nw));
  ;
  vector<long long> dp(n + 1, 0);
  dp[1] = 1;
  ;
  for (long long i = 1; i <= n; ++i) {
    for (long long x : nw) {
      if (i - x >= 1) {
        dp[i] = (dp[i] + dp[i - x]) % mod;
      }
    }
  }
  cout << dp[n];
}
