#include <bits/stdc++.h>
using namespace std;
vector<long long int> dp;
long long int n;
set<long long int> segment;
long long int findleaps(long long int i) {
  if (dp[i] != -1) return dp[i];
  long long int ans = 0;
  for (auto k : segment) {
    if (k + i > n) break;
    ans = (ans + findleaps(k + i)) % 998244353;
  }
  dp[i] = ans;
  return dp[i];
}
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 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];
    for (long long int i = 1; i < n + 1; i++) {
      if (line[i] > 0) segment.insert(i);
    }
    dp = vector<long long int>(n + 1, -1);
    dp[n] = 1;
    cout << findleaps(1);
  }
  return 0;
}
