#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:100000000")
#pragma comment(linker, "/HEAP:100000000")
using namespace std;
template <typename T>
void print_mat(vector<vector<T>>& mat) {
  for (int i = 0; i < mat.size(); i++) {
    for (int j = 0; j < mat[i].size(); j++) {
      cout << mat[i][j] << ' ';
    }
    cout << endl;
  }
}
int neg_mod(int a, int b) { return (b + (a % b)) % b; }
void solve() {
  int n, k;
  cin >> n >> k;
  vector<pair<int, int>> segs;
  vector<int> s;
  for (int i = 0; i < k; i++) {
    int l, r;
    cin >> l >> r;
    segs.push_back({l, r});
  }
  sort(segs.begin(), segs.end());
  for (auto seg : segs) {
    for (int k = seg.first; k <= seg.second; k++) s.push_back(k);
  }
  vector<int> dp(n + 1);
  dp[0] = 0;
  dp[1] = 1;
  for (int i = 2; i <= n; i++) {
    for (int el : s) {
      if (i - el >= 0) {
        dp[i] = (dp[i] + dp[i - el]) % 998244353;
      } else
        break;
    }
  }
  cout << dp[n] << endl;
}
int main() {
  solve();
  return 0;
}
