#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
using ll = long long;
const ll INF_ll = 1e17;
const int INF = 1e8;
int main() {
  ll MOD = 998244353;
  int N, K;
  cin >> N >> K;
  vector<vector<int>> lr(K, vector<int>(2));
  vector<int> d(0);
  for (int i = 0; i < K; i++) {
    int l, r;
    cin >> l >> r;
    for (int j = l; j <= r; j++) {
      d.push_back(j);
    }
  }
  sort(d.begin(), d.end());
  vector<ll> dp(N + 1, 0);
  dp[1] = 1;
  for (int i = 1; i < N + 1; i++) {
    for (int j = 0; j < d.size(); j++) {
      if (i < d[j]) {
        continue;
      }
      dp[i] += dp[i - d[j]];
      dp[i] %= MOD;
    }
  }
  cout << dp[N] << endl;
  return 0;
}
