#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5, INF = 1E9 + 7;
long double EPS = 1e-9;
inline long long add(long long x, long long y) {
  x += y;
  if (x >= 998244353) x -= 998244353;
  return x;
}
inline long long sub(long long x, long long y) {
  x -= y;
  if (x < 0) x += 998244353;
  return x;
}
inline long long mul(long long x, long long y) {
  return (x % 998244353 * 1ll * y % 998244353) % 998244353;
}
inline long long pwr(long long a, long long b) {
  long long x = 1 % 998244353;
  while (b) {
    if (b & 1) x = mul(x, a);
    a = mul(a, a);
    b >>= 1;
  }
  return x % 998244353;
}
inline long long inv(long long a) { return pwr(a, 998244353 - 2) % 998244353; }
long long gcd(long long a, long long b) {
  if (!a) return b % 998244353;
  return gcd(b % a, a) % 998244353;
}
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cout << name << " : " << arg1 << "\n";
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cout.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
map<long long, long long> m;
set<long long> second;
long long n, k;
long long recur(long long currPos) {
  if (currPos == n) {
    return 1;
  }
  if (currPos > n) {
    return 0;
  }
  if (m.find(currPos) != m.end()) return m[currPos] % 998244353;
  long long ans = 0;
  for (auto i : second) {
    ans = add(ans, recur(currPos + i));
  }
  return m[currPos] = ans % 998244353;
}
void solve() {
  cin >> n >> k;
  for (long long i = 0; i < k; i++) {
    long long l, r;
    cin >> l >> r;
    for (long long j = l; j <= r; j++) {
      second.insert(j);
    }
  }
  cout << recur(1) << "\n";
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long tc;
  tc = 1;
  while (tc--) {
    solve();
  }
}
