#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
constexpr int INF = 1 << 30;
constexpr ll MOD = ll(998244353);
int n, k;
vector<int> s;
vector<ll> dp;
int main(void) {
  cin >> n >> k;
  for (int i = 0; i < k; i++) {
    int li, ri;
    cin >> li >> ri;
    for (int j = li; j <= ri; j++) s.push_back(j);
  }
  sort(s.begin(), s.end());
  int m = s.size();
  dp = vector<ll>(n, 0);
  dp[0] = 1;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m && s[j] <= i; j++) {
      dp[i] = (dp[i] + dp[i - s[j]]) % MOD;
    }
  }
  cout << dp[n - 1] << endl;
  return 0;
}
