#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout << fixed << setprecision(10);
  long long int t = 1;
  while (t--) {
    long long int n, k;
    cin >> n >> k;
    vector<long long int> line(n + 2, 0);
    for (long long int i = 0; i < k; i++) {
      long long int l, r;
      cin >> l >> r;
      line[l]++;
      line[r + 1]--;
    }
    for (long long int i = 1; i < n + 1; i++) line[i] += line[i - 1];
    set<long long int> segment;
    for (long long int i = 1; i < n + 1; i++) {
      if (line[i] > 0) segment.insert(i);
    }
    vector<long long int> dp(n + 1, 0);
    dp[n] = 1;
    for (long long int i = n - 1; i > 0; i--) {
      for (auto k : segment) {
        long long int x = k;
        if (i + x <= n)
          dp[i] = (dp[i] + dp[i + x]) % 998244353;
        else
          break;
      }
    }
    cout << dp[1];
  }
  return 0;
}
