#include <bits/stdc++.h>
using namespace std;
const long long mod = 998244353;
template <typename T>
void debug(vector<T> x) {
  for (auto e : x) {
    cout << e << " ";
  }
  cout << "\n";
}
void solve() {
  long long n, k;
  cin >> n >> k;
  vector<long long> dp(n + 1, 0);
  dp[1] = 1;
  vector<bool> helper(n + 1);
  for (long long i = 0; i < k; i++) {
    long long x, y;
    cin >> x >> y;
    for (long long j = x; j <= y; j++) helper[j] = true;
  }
  vector<long long> steps;
  for (long long i = 1; i <= n; i++) {
    if (helper[i]) steps.push_back(i);
  }
  long long m = steps.size();
  for (long long i = 1; i < n; i++) {
    if (dp[i] <= 0) continue;
    for (long long j = 0; j < m; j++) {
      if (i + steps[j] <= n) {
        dp[i + steps[j]] = (dp[i + steps[j]] + dp[i]) % mod;
      }
    }
  }
  cout << dp[n];
  cout << "\n";
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long t = 1;
  for (long long i = 1; i <= t; i++) {
    solve();
  }
  return 0;
}
