#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  vector<int> a;
  for (int i = 0; i < k; i++) {
    int l, r;
    cin >> l >> r;
    for (int j = l; j <= r; j++) a.push_back(j);
  }
  sort(a.begin(), a.end());
  vector<ll> dp(n + 1);
  constexpr ll MOD = 998244353;
  dp[0] = 1;
  for (int i = 0; i < n; i++) {
    for (int e : a) {
      if (i + e >= n) break;
      dp[i + e] += dp[i];
      dp[i + e] %= MOD;
    }
  }
  cout << dp[n - 1] << "\n";
}
