#include <bits/stdc++.h>
using namespace std;
void err(istream_iterator<string> it) {
  cout << '\n';
  ;
}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " = " << a << ", ";
  err(++it, args...);
}
template <typename T>
inline void Int(T &n) {
  n = 0;
  int f = 1;
  register int ch = getchar();
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-') f = -1;
  for (; isdigit(ch); ch = getchar()) n = (n << 3) + (n << 1) + ch - '0';
  n = n * f;
}
template <typename T, typename TT>
inline void Int(T &n, TT &m) {
  Int(n);
  Int(m);
}
template <typename T, typename TT, typename TTT>
inline void Int(T &n, TT &m, TTT &l) {
  Int(n, m);
  Int(l);
}
double ind() {
  double x;
  scanf("%lf", &x);
  return x;
}
int set_1(int n, int pos) { return n = (n | (1 << pos)); }
int reset_0(int n, int pos) { return n = n & ~(1 << pos); }
bool check_bit(int n, int pos) { return n = n & (1 << pos); }
int dx[8] = {1, 0, -1, 0, -1, -1, 1, 1};
int dy[8] = {0, 1, 0, -1, -1, 1, -1, 1};
const int N = (int)1e6 + 5;
const long long M = (long long)998244353;
const double pi = 2 * acos(0.0);
const double eps = 1e-9;
std::vector<int> v;
long long dp[N];
int n, k;
long long f(int pos) {
  if (pos == 1) return 1ll;
  if (dp[pos] != -1) return dp[pos];
  long long res = 0;
  for (int i = 0; i < (int)v.size(); ++i) {
    if (pos - v[i] >= 1) {
      res = (res + f(pos - v[i])) % M;
    }
  }
  return dp[pos] = res;
}
int main() {
  Int(n, k);
  memset(dp, -1, sizeof(dp));
  set<int> s;
  for (int i = 1; i <= k; ++i) {
    int l, r;
    Int(l, r);
    for (int j = l; j <= r; ++j) {
      s.insert(j);
    }
  }
  for (auto x : s) {
    v.push_back(x);
  }
  long long res = f(n);
  printf("%lld\n", res);
  return 0;
}
