#include <bits/stdc++.h>
using namespace std;
const long long mod = 998244353;
int n;
vector<int> v;
int main() {
  cin >> n;
  int k;
  cin >> k;
  vector<int> dic(n + 1);
  for (int i = 0; i < (k); i++) {
    int l, r;
    cin >> l >> r;
    dic[l]++;
    if (r + 1 <= n) dic[r + 1]--;
  }
  for (int i = 0; i < (n); i++) {
    dic[i + 1] += dic[i];
  }
  for (int i = 1; i <= n; i++) {
    if (dic[i] > 0) v.push_back(i);
  }
  vector<long long> dp(n + 1);
  dp[1] = 1;
  for (int i = 1; i < n; i++) {
    for (int j = 0; j < (v.size()); j++) {
      if (i + v[j] <= n)
        (dp[i + v[j]] += dp[i]) %= mod;
      else
        break;
    }
  }
  cout << dp[n] << endl;
}
