#include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;
using lint = long long;
using ll = long long;
const lint inf = 1e18 + 7;
const int MOD = 998244353;
signed main() {
  int n, k;
  cin >> n >> k;
  vector<int> a;
  for (int i = 0; i < k; ++i) {
    int l, r;
    cin >> l >> r;
    for (int j = l; j <= r; ++j) a.push_back(j);
  }
  vector<int> dp(n + 1, 0);
  dp[1] = 1;
  int num = a.size();
  sort(a.begin(), a.end());
  for (int j = 1; j < n; ++j) {
    for (int i = 0; i < num; ++i) {
      if (a[i] + j > n) break;
      dp[a[i] + j] += dp[j];
      dp[a[i] + j] %= MOD;
    }
  }
  cout << dp[n] << "\n";
  return 0;
}
