#include <bits/stdc++.h>
using namespace std;
constexpr int MOD = 998244353;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, k;
  cin >> n >> k;
  vector<int> l(k), r(k);
  for (int i = 0; i < k; i++) cin >> l[i] >> r[i];
  vector<int> dp(2 * n + 100);
  dp[1] = 1;
  for (int i = 1; i < n; i++) {
    for (int j = 0; j < k; j++) {
      for (int kk = l[j]; kk <= min(n, r[j]); kk++) {
        (dp[i + kk] += dp[i]) %= MOD;
      }
    }
  }
  cout << dp[n] << "\n";
  return 0;
}
