#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];
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);
}
inline long long sub(long long x, long long y, long long mod) {
  x -= y;
  if (x + mod <= 0) {
    x %= mod;
  }
  return (x < 0 ? 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;
    vector<long long> dp(2 * n + 1);
    vector<pair<long long, long long>> v(m);
    for (long long j = 0; j < m; j++) {
      long long x, y;
      cin >> v[j].first >> v[j].second;
    }
    sort(v.begin(), v.end());
    long long ans;
    dp[1] = 1;
    dp[2] = 998244353 - 1;
    for (long long i = 1; i <= n; i++) {
      dp[i + 1] += dp[i];
      dp[i] %= 998244353;
      for (long long j = 0; j < m; j++) {
        long long l = v[j].first;
        long long r = v[j].second;
        dp[i + l] += dp[i];
        dp[i + r + 1] -= dp[i];
      }
    }
    ans = dp[n];
    cout << ans;
  }
  return 0;
}
