#include <bits/stdc++.h>
using namespace std;
long long int n, k;
long long int dp[200001];
bool boosted[200001];
vector<long long int> valid;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> k;
  for (long long int i = 0; i < k; i++) {
    long long int a, b;
    cin >> a >> b;
    a--, b--;
    for (long long int i = a; i <= b; i++) boosted[i] = true;
  }
  for (long long int i = 0; i < n; i++)
    if (boosted[i]) valid.push_back(i);
  long long int ptr = 0, sum = 0;
  dp[n - 1] = 1;
  for (long long int i = n - 2; i >= 0; i--) {
    dp[i] = 0;
    for (long long int j = 0; j < valid.size(); j++) {
      ptr = j;
      if (i + valid[j] + 1 >= n) break;
      dp[i] = (dp[i] + dp[i + valid[j] + 1]) % 998244353;
    }
  }
  cout << dp[0] << endl;
}
