#include <bits/stdc++.h>
using namespace std;
int dp[200005];
int br[200005];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, k;
  cin >> n >> k;
  vector<int> v;
  for (int i = 1; i <= k; i++) {
    int a, b;
    cin >> a >> b;
    br[a]++;
    br[b + 1]--;
  }
  for (int i = 1; i <= n; i++) {
    br[i] += br[i - 1];
    if (br[i] == 0)
      continue;
    else
      v.push_back(i);
  }
  sort(v.begin(), v.end());
  dp[1] = 1;
  for (int i = 2; i <= n; i++) {
    for (int j = 0; j < v.size(); j++) {
      if (i - v[j] >= 1) {
        dp[i] += dp[i - v[j]];
        dp[i] %= 998244353;
      } else
        break;
    }
  }
  cout << dp[n] << "\n";
  return 0;
}
