#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long m, n;
  long long i, j;
  cin >> n >> m;
  vector<long long> us;
  long long x, y;
  for (i = (0); i < (m); i++) {
    cin >> x >> y;
    for (j = (x); j <= (y); j++) us.push_back(j);
  }
  vector<long long> dp(n + 1);
  dp[1] = 1;
  for (i = (1); i <= (n); i++) {
    if (dp[i] == 0) continue;
    for (long long x : us) {
      if (i + x <= n) {
        dp[i + x] =
            (dp[i + x] % 998244353LL + dp[i] % 998244353LL) % 998244353LL;
      }
    }
  }
  cout << dp[n] << '\n';
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  solve();
  return 0;
}
