#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
void err(istream_iterator<string> it) {}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " = " << a << ", ";
  err(++it, args...);
  cout << "\n";
}
long long powm(long long a, long long b, long long mod) {
  long long res = 1;
  while (b) {
    if (b & 1) res = (res * a) % mod;
    a = (a * a) % mod;
    b >>= 1;
  }
  return res;
}
const long long mod = 998244353;
const long long N = 1000005;
const long long inf = 1e9;
void solve() {
  int n, k;
  cin >> n >> k;
  vector<int> seg;
  for (long long i = 0; i < (k); i++) {
    int x, y;
    cin >> x >> y;
    for (long long j = (x); j < (y + 1); j++) seg.push_back(j);
  }
  vector<long long> dp(n + 1, 0);
  sort(seg.begin(), seg.end());
  dp[1] = 1;
  for (long long i = (1); i < (n); i++) {
    for (int j : seg) {
      if (i + j <= n) {
        dp[i + j] += dp[i];
        dp[i + j] %= mod;
      } else
        break;
    }
  }
  cout << dp[n] << '\n';
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);
  int tc = 1;
  while (tc--) {
    solve();
  }
  return 0;
}
