#include <bits/stdc++.h>
using namespace std;
const int INF = 1001001001;
const int LIMIT = 998244353;
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> s;
  int l, r;
  for (int(j) = 0; (j) < (k); ++(j)) {
    cin >> l >> r;
    for (int i = l - 1; i < r; i++) s.push_back(i + 1);
  }
  vector<long long> dp(n + 1, 0);
  for (int(i) = 0; (i) < (s.size()); ++(i)) dp[s[i] - 1] = 1;
  int b = s.size();
  for (int(i) = 0; (i) < (n); ++(i)) {
    for (int j = 0; j < b; j++) {
      if (i - s[j] >= 0) {
        dp[i] += dp[i - s[j]];
        dp[i] %= LIMIT;
      }
    }
  }
  cout << dp[n - 2] << endl;
  return 0;
}
