#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e12;
const long long MOD = 998244353;
const long long mod = 1e9 + 7;
template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
  for (T i : v) os << i << ' ';
  return os;
}
template <class T>
ostream& operator<<(ostream& os, const set<T>& v) {
  for (T i : v) os << i << ' ';
  return os;
}
template <class T, class S>
ostream& operator<<(ostream& os, const pair<T, S>& v) {
  os << v.first << ' ' << v.second;
  return os;
}
template <class T, class S>
ostream& operator<<(ostream& os, const unordered_map<T, S>& v) {
  for (auto i : v) os << '(' << i.first << "=>" << i.second << ')' << ' ';
  return os;
}
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target( \
    "avx2,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
clock_t time_p = clock();
void starboy1299() {
  time_p = clock() - time_p;
  cerr << "Time Taken : " << (float)(time_p) / CLOCKS_PER_SEC << "\n";
}
void fast() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
}
inline long long mul(long long a, long long b, long long m = mod) {
  return (a * b) % m;
}
inline long long add(long long a, long long b, long long m = mod) {
  return (a + b) % m;
}
inline long long sub(long long a, long long b, long long m = mod) {
  return (a - b + m) % m;
}
const long long N = 2e6 + 5;
long long dp[N];
unordered_set<long long> s;
long long n;
long long f(long long idx) {
  if (idx > n) return 0;
  if (idx == n) {
    return 1;
  }
  if (dp[idx] != -1) return dp[idx];
  long long ans = 0;
  for (long long i = 1; i < n + 1; i++) {
    if (s.count(i)) {
      ans += f(idx + i) % MOD;
    }
  }
  return dp[idx] = ans % MOD;
}
void solve() {
  long long k;
  cin >> n >> k;
  for (long long i = 1; i <= n; i++) {
    dp[i] = -1;
  }
  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);
    }
  }
  cout << f(1) << '\n';
}
int32_t main() {
  fast();
  long long t = 1;
  for (long long i = 1; i <= t; i++) {
    solve();
  }
  starboy1299();
}
