#include <bits/stdc++.h>
using namespace std;
int mod = 998244353;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, k;
  cin >> n >> k;
  vector<pair<int, int>> intervals(k);
  for (int i = 0; i < k; ++i) cin >> intervals[i].first >> intervals[i].second;
  vector<long long> dp(n + 1, 0);
  dp[n] = 1;
  for (int i = n - 1; i >= 1; --i) {
    for (auto Int : intervals) {
      if (Int.first > n - i) continue;
      int m = min(n - i, Int.second);
      for (int j = Int.first; j <= m; ++j) {
        dp[i] += dp[i + j];
        if (dp[i] >= mod) dp[i] -= mod;
      }
    }
  }
  cout << dp[1] << "\n";
  return 0;
}
