#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
const long long mod = 998244353;
const long long INF = 1LL << 60;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
void chmin(long long& a, long long b) {
  if (a > b) a = b;
}
void chmax(long long& a, long long b) {
  if (a < b) a = b;
}
struct mint {
  long long x;
  mint(long long x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod - a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const { return mint(*this) += a; }
  mint operator-(const mint a) const { return mint(*this) -= a; }
  mint operator*(const mint a) const { return mint(*this) *= a; }
  mint pow(long long t) const {
    if (!t) return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1) a *= *this;
    return a;
  }
  mint inv() const { return pow(mod - 2); }
  mint& operator/=(const mint a) { return *this *= a.inv(); }
  mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream& is, mint& a) { return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }
int main(void) {
  ios::sync_with_stdio(0);
  cin.tie(0);
  mint dp[200005] = {};
  dp[0] = 1;
  int N, K;
  cin >> N >> K;
  vector<pair<int, int>> data;
  while (K--) {
    int L, R;
    cin >> L >> R;
    data.push_back(make_pair(L, R));
  }
  for (int i = 0; i < (N); i++) {
    for (int j = 0; j < (data.size()); j++) {
      int f = data.at(j).first, s = data.at(j).second;
      for (int k = f; k < (s + 1); k++) {
        if (i + k <= N) {
          dp[i + k] += dp[i];
        }
      }
    }
  }
  cout << dp[N - 1] << "\n";
  return 0;
}
