#include <bits/stdc++.h>
using namespace std;
template <class T>
using pq = priority_queue<T>;
template <class T>
using pqg = priority_queue<T, vector<T>, greater<T>>;
template <class T, class S>
inline bool chmax(T &a, S b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T, class S>
inline bool chmin(T &a, S b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
void line(vector<T> &x) {
  for (auto &&xi : x) cin >> xi;
}
inline void IN(void) { return; }
template <typename First, typename... Rest>
void IN(First &first, Rest &...rest) {
  cin >> first;
  IN(rest...);
  return;
}
template <class T>
void UNIQUE(vector<T> &x) {
  sort((x).begin(), (x).end());
  x.erase(unique((x).begin(), (x).end()), x.end());
}
template <class T>
void print_vec(T first, T end) {
  for (auto i = first; i < end - 1; i++) cout << *i << " ";
  cout << *(end - 1) << "\n";
}
template <class... T>
void debug_print(T... args) {
  vector<long long> tmp = initializer_list<long long>{args...};
  print_vec((tmp).begin(), (tmp).end());
}
template <class T>
void print(T a) {
  cout << a << "\n";
}
vector<string> Yes = {"No", "Yes"};
vector<string> YES = {"NO", "YES"};
int ord(char x) { return (int)(x - 'a'); }
char chr(long long x) { return (char)(x + (long long)('a')); }
long long mod = 1e9 + 7;
long long sum(vector<long long> a) {
  long long ret = 0;
  for (auto &&v : a) ret += v;
  return ret;
}
long long vmini(vector<long long> a, long long &index) {
  long long ret = LLONG_MAX;
  for (int i = 0; i < (int)((int)(a).size()); i++) {
    if (chmin(ret, a[i])) index = i;
  }
  return ret;
}
long long vmaxi(vector<long long> a, long long &index) {
  long long ret = -LLONG_MAX;
  for (int i = 0; i < (int)((int)(a).size()); i++) {
    if (chmax(ret, a[i])) index = i;
  }
  return ret;
}
long long vmin(vector<long long> a) {
  long long ret = LLONG_MAX;
  for (auto &&v : a) chmin(ret, v);
  return ret;
}
long long vmax(vector<long long> a) {
  long long ret = -LLONG_MAX;
  for (auto &&v : a) chmax(ret, v);
  return ret;
}
vector<long long> base_3(int k) {
  vector<long long> ret;
  while (k > 0) {
    ret.push_back(k % 3);
    k /= 3;
  }
  reverse((ret).begin(), (ret).end());
  return ret;
}
map<long long, long long> trial_division(long long n) {
  map<long long, long long> factor;
  long long tmp = (long long)(sqrt(n)) + 1;
  for (long long i = 2; i < tmp; ++i) {
    while (n % i == 0) {
      n /= i;
      factor[i]++;
    }
  }
  if (n != 1) factor[n]++;
  return factor;
}
long long dist(long long x1, long long y1, long long x2, long long y2) {
  return (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);
}
vector<long long> ans = vector<long long>();
long long calc(long long x, vector<long long> arr, long long y) {
  if (ans[x] != -1) return ans[x];
  if (x <= 0) return 1;
  long long ret = 0;
  for (int i = 0; i < (int)(y); i++) {
    if (x - arr[i] >= 0) {
      ret += calc(x - arr[i], arr, y);
      ret %= 998244353;
    }
  }
  ans[x] = ret;
  return ans[x];
}
int main() {
  long long n, k;
  IN(n, k);
  vector<long long> a = vector<long long>(n + 1, LLONG_MAX);
  long long l, r;
  long long index = 0;
  for (int i = 0; i < (int)(k); i++) {
    IN(l, r);
    for (long long j = l; j <= r; j++) {
      a[index] = j;
      index += 1;
    }
  }
  sort((a).begin(), (a).end());
  ans.assign(n + 1, -1);
  print(calc(n - 1, a, index));
}
