#include <bits/stdc++.h>
using namespace std;
template <typename T>
static inline void ArrayInput(vector<T> &A) {
  for (auto itr = A.begin(); itr < A.end(); ++itr) cin >> *itr;
}
template <typename T>
static inline void ArrayPut(const vector<T> &A) {
  for (auto itr = A.begin(); itr < A.end(); ++itr) cout << *itr << " ";
  cout << endl;
}
template <typename T>
static inline T ArraySum(vector<T> &A) {
  T res = 0;
  for (auto itr = A.begin(); itr < A.end(); ++itr) res += *itr;
  return res;
}
bool Sec_compare(pair<uint64_t, uint64_t> a, pair<uint64_t, uint64_t> b) {
  if (a.second != b.second) {
    return a.second < b.second;
  } else {
    return a.first > b.first;
  }
}
uint64_t dec_dig(uint64_t num) {
  uint64_t res = 0;
  while (num > 0) {
    num /= 10;
    ++res;
  }
  return res;
}
int64_t modinv(int64_t a, int64_t m) {
  int64_t b = m, u = 1, v = 0;
  while (b) {
    int64_t t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  u %= m;
  if (u < 0) u += m;
  return u;
}
uint64_t gcd(uint64_t a, uint64_t b) {
  if (a < b) {
    a ^= b;
    b ^= a;
    a ^= b;
  }
  return b ? gcd(b, a % b) : a;
}
int64_t My_Comb(uint64_t n, uint64_t k, int64_t m) {
  if (n < k) return 0;
  if (k == 0 || n == k) return 1;
  uint64_t res = 1;
  k = (n / 2 < k) ? n - k : k;
  for (uint64_t i = 1; i <= k; ++i)
    res = (((res * (n + 1 - i)) % m) * modinv(i, m)) % m;
  return res;
}
int64_t My_Pow(uint64_t a, uint64_t n, int64_t m) {
  uint64_t tmp = n, calc = 1;
  while (tmp > 0) {
    if (tmp % 2) {
      tmp--;
      calc *= a;
      calc %= m;
    } else {
      a *= a;
      a %= m;
      tmp /= 2;
    }
  }
  return calc;
}
class UnionFind {
 public:
  vector<uint64_t> Par;
  vector<uint64_t> sz;
  UnionFind(uint64_t n);
  uint64_t root(uint64_t x);
  bool same(uint64_t x, uint64_t y);
  void unite(uint64_t x, uint64_t y);
  uint64_t size(uint64_t x);
};
UnionFind::UnionFind(uint64_t n) {
  Par.resize(n);
  sz.assign(n, 1);
  for (uint64_t i = 0; i < n; ++i) Par[i] = i;
}
uint64_t UnionFind::root(uint64_t x) {
  if (Par[x] == x) {
    return x;
  } else {
    return Par[x] = root(Par[x]);
  }
}
bool UnionFind::same(uint64_t x, uint64_t y) { return root(x) == root(y); }
uint64_t UnionFind::size(uint64_t x) { return sz[root(x)]; }
void UnionFind::unite(uint64_t x, uint64_t y) {
  x = root(x);
  y = root(y);
  if (x == y) return;
  if (sz[x] < sz[y]) swap(x, y);
  sz[x] += sz[y];
  Par[y] = x;
}
vector<int64_t> p;
std::vector<bool> is_prime(1000000 + 1, true);
void Eratosthenes(const int N) {
  for (int i = 2; i <= N; i++) {
    if (is_prime[i]) {
      for (int j = 2 * i; j <= N; j += i) {
        is_prime[j] = false;
      }
      p.emplace_back(i);
    }
  }
}
int64_t Calc(int64_t N) {
  int64_t res = 1;
  int64_t org_N = N;
  if (N == 1) return 1;
  for (auto itr = p.begin(); (*itr) <= org_N; ++itr) {
    int64_t cnt = 0;
    if (N == 1) break;
    if (is_prime[N]) return res * 2;
    while (N % (*itr) == 0) {
      N /= (*itr);
      ++cnt;
    }
    res *= (cnt + 1);
  }
  return res;
}
int main() {
  cout << setprecision(18);
  uint32_t N, K;
  cin >> N >> K;
  set<uint64_t> S;
  for (uint32_t i = 0; i < K; ++i) {
    uint32_t l, r;
    cin >> l >> r;
    for (; l <= r; ++l) S.insert(l);
  }
  vector<uint64_t> dp((2 * N) + 10, 0);
  dp[1] = 1;
  for (uint32_t i = 1; i < N; ++i) {
    for (auto itr = S.begin(); itr != S.end(); ++itr) {
      dp[i + *itr] += dp[i];
      dp[i + *itr] %= (998244353);
    }
  }
  cout << dp[N] % (998244353) << endl;
  return 0;
}
