#include <bits/stdc++.h>
using namespace std;
using Int = long long int;
int Mod = 998244353;
int main() {
  int n, k;
  cin >> n >> k;
  set<int> es;
  for (int i = 0; i < k; i++) {
    int l, r;
    cin >> l >> r;
    for (int i = l; i <= r; i++) {
      es.insert(i);
    }
  }
  vector<int> dp(n, 0);
  queue<int> todo;
  dp[0] = 1;
  for (int i = 1; i < n; i++) {
    for (auto a : es) {
      if (i >= a) dp[i] += dp[i - a] % Mod;
      dp[i] %= Mod;
    }
  }
  cout << dp[n - 1] << endl;
}
