#include <bits/stdc++.h>
using namespace std;
const long long mod = 998244353;
void DBG() { cerr << "]\n"; }
template <typename T, typename... Args>
void DBG(T first, Args... args) {
  cerr << first;
  if (sizeof...(args)) cerr << ", ";
  DBG(args...);
}
long long add(long long x, long long y) {
  long long res = x + y;
  if (res >= mod) res -= mod;
  return res;
}
void solve() {
  long long n, k;
  cin >> n >> k;
  set<long long> s;
  for (long long i = (0); i < (k); (i)++) {
    long long a, b;
    cin >> a >> b;
    for (long long i = (a); i <= (b); (i)++) s.insert(i);
  }
  long long dp[n];
  memset(dp, 0, sizeof(dp));
  dp[0] = 1;
  for (long long i = (1); i < (n); (i)++) {
    for (auto(ele) : (s)) {
      if (i >= ele) dp[i] = add(dp[i - ele], dp[i]);
    }
  }
  cout << dp[n - 1] << "\n";
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  long long t = 1;
  for (long long tt = 1; tt <= t; tt++) {
    solve();
  }
}
