#include <bits/stdc++.h>
using namespace std;
const int INF = 1001001001;
const long long MX = 1e18;
const int mod = 998244353;
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
int main() {
  int n;
  cin >> n;
  int k;
  cin >> k;
  vector<int> s;
  for (int ki = 0; ki < (int)(k); ki++) {
    int l, r;
    cin >> l >> r;
    for (int i = l; i <= r; i++) s.push_back(i);
  }
  sort(s.begin(), s.end());
  vector<int> dp(n + 1);
  dp[1] = 1;
  for (int i = 2; i <= n; i++) {
    for (int j = 0; j < (int)(s.size()); j++) {
      if (i - s[j] < 1) break;
      dp[i] += dp[i - s[j]];
      dp[i] %= mod;
    }
  }
  cout << dp[n] << endl;
}
