#include <bits/stdc++.h>
using namespace std;
using ull = unsigned long long;
using ll = long long;
int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n, k;
  cin >> n >> k;
  unordered_set<int> S{};
  vector<ull> dp(n + 1, 0);
  for (int i = 0; i < k; i++) {
    int l, r;
    cin >> l >> r;
    vector<int> v(r - l + 1, 0);
    std::iota(v.begin(), v.end(), l);
    S.insert(v.begin(), v.end());
  }
  dp[1] = 1;
  for (int j = 1; j <= n; j++) {
    for (auto&& i : S) {
      if (j - i > 0) {
        dp[j] += dp[j - i];
      }
    }
  }
  cout << (dp[n] % 998244353) << endl;
}
