#include <bits/stdc++.h>
using namespace std;
void solve(int test) {
  long long n;
  cin >> n;
  long long hell = 998244353;
  long long i, j;
  vector<long long> dp(n + 1, 0LL);
  long long k;
  cin >> k;
  vector<pair<long long, long long> > v(k);
  vector<long long> moves;
  for (i = 0; i < k; i++) {
    cin >> v[i].first;
    cin >> v[i].second;
    for (j = v[i].first; j <= v[i].second; j++) moves.push_back(j);
  }
  sort(moves.begin(), moves.end());
  dp[1] = 1;
  for (i = 2; i <= n; i++) {
    int lb = lower_bound(moves.begin(), moves.end(), i) - moves.begin();
    if (lb == 0) continue;
    for (j = 0; j < lb; j++) {
      dp[i] = (dp[i] + dp[i - moves[j]]) % hell;
    }
  }
  cout << dp[n] << endl;
  return;
}
int main() {
  int t = 1;
  for (int x = 1; x <= t; x++) {
    solve(x);
  }
  return 0;
}
