#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long n, k;
  cin >> n >> k;
  long long x, y;
  vector<long long> coin;
  for (int i = 0; i < k; i++) {
    cin >> x >> y;
    for (long long j = x; j <= y; j++) coin.push_back(j);
  }
  long long dp[n];
  memset(dp, 0, sizeof(dp));
  dp[0] = 1;
  for (int x = 1; x < n; x++) {
    for (auto p : coin) {
      if (x - p >= 0) dp[x] = (dp[x] + dp[x - p]) % (long long)(998244353);
    }
  }
  cout << dp[n - 1] << endl;
}
int main() {
  int t = 1;
  for (int i = 1; i <= t; i++) {
    solve();
  }
  return 0;
}
