#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
const long long N = 2e6 + 5;
const long long INF = 1e18L;
vector<string> split(const string& s, char c) {
  vector<string> v;
  stringstream ss(s);
  string x;
  while (getline(ss, x, c)) v.emplace_back(x);
  return move(v);
}
template <typename T, typename... Args>
inline string arrStr(T arr, long long n) {
  stringstream s;
  s << "[";
  for (long long i = 0; i < n - 1; i++) s << arr[i] << ",";
  if (n > 0) s << arr[n - 1];
  s << "]";
  return s.str();
}
inline void __trace_begin(long long line) { cerr << "#" << line << ": "; }
template <typename T>
inline void __trace_out_var(vector<T> val) {
  cerr << arrStr(val, val.size());
}
template <typename T>
inline void __trace_out_var(T* val) {
  cerr << arrStr(val, 10);
}
template <typename T>
inline void __trace_out_var(T val) {
  cerr << val;
}
inline void __trace(vector<string>::iterator it) { cerr << '\n'; }
template <typename T, typename... Args>
inline void __trace(vector<string>::iterator it, T a, Args... args) {
  cerr << it->substr((*it)[0] == ' ', it->length()) << "=";
  __trace_out_var(a);
  cerr << "; ";
  __trace(++it, args...);
}
long long ar[N];
long long dp[N];
vector<long long> v;
inline long long add(long long x, long long y, long long mod) {
  if (y >= mod) y %= mod;
  if (x >= mod) x %= mod;
  x += y;
  return (x >= mod ? x - mod : x);
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ;
  long long T = 1;
  while (T--) {
    long long n, m;
    cin >> n >> m;
    for (long long j = 0; j < m; j++) {
      long long x, y;
      cin >> x >> y;
      for (long long i = x; i <= y; i++) v.push_back(i), dp[i]++;
    }
    sort(v.begin(), v.end());
    long long sz = v.size();
    for (long long j = v[0]; j < n; j++) {
      long long ii = upper_bound(v.begin(), v.end(), j) - v.begin();
      for (long long i = 0; i < min(sz, ii); i++) {
        dp[j] = add(dp[j], dp[j - v[i]], 998244353);
      }
    }
    long long ans = dp[n - 1];
    cout << ans;
  }
  return 0;
}
