#include <bits/stdc++.h>
using namespace std;
vector<int> s;
vector<unsigned long long int> dp;
vector<int> tmp;
int main() {
  int n, k;
  cin >> n >> k;
  for (int i = 0; i < k; i++) {
    int t1, t2;
    cin >> t1 >> t2;
    tmp.push_back(t1);
    tmp.push_back(t2);
  }
  sort(tmp.begin(), tmp.end());
  for (int i = 0; i < 2 * k; i = i + 2)
    for (int j = tmp[i]; j <= tmp[i + 1]; j++) s.push_back(j);
  dp.resize(n + s[s.size() - 1], 0);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < s.size(); j++) {
      dp[i + s[j]] += dp[i] + 1;
    }
  }
  cout << (dp[n - 1] - 1) % 998244353 << endl;
}
