#include <bits/stdc++.h>
using namespace std;
long long n, k;
vector<long long> v;
long long dp[300001];
long long query(int n) {
  if (n == 1) return 1;
  if (dp[n] != -1) return dp[n];
  long long answer = 0;
  for (int i = 0; i < v.size(); i++) {
    if (n - v[i] >= 1) {
      answer += query(n - v[i]);
      answer %= 998244353;
    } else
      break;
  }
  return dp[n] = answer % 998244353;
}
int main() {
  memset(dp, -1, sizeof(dp));
  cin >> n >> k;
  vector<int> mapper(n + 1, 0);
  for (int i = 0; i < k; i++) {
    int a, b;
    cin >> a >> b;
    mapper[a]++;
    mapper[b + 1]--;
  }
  int running_sum = 0;
  for (int i = 1; i <= n; i++) {
    running_sum += mapper[i];
    if (running_sum > 0) v.push_back(i);
  }
  cout << query(n) << endl;
  return 0;
}
