#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
vector<pair<ll, int>> factorize(ll n) {
  vector<pair<ll, int>> res;
  for (ll i = 2; i * i <= n; i++) {
    if (n % i) continue;
    res.emplace_back(i, 0);
    while (n % i == 0) {
      n /= i;
      res.back().second++;
    }
  }
  if (n != 1) res.emplace_back(n, 1);
  return res;
}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll ceil(ll a, ll b) { return (a + b - 1) / b; }
const ll INF = LONG_MAX;
template <class T>
inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
const int dw[4] = {-1, 0, 0, 1};
const int dh[4] = {0, -1, 1, 0};
const int dww[22] = {-2, -1, 0,  1, 2,     -2, -1, 1, 2, -2,
                     2,  -2, -1, 1, 2 - 2, -1, 0,  1, 2};
const int dhw[22] = {-2, -2, -2, -2, -2, -1, -1, -1, -1, 0,
                     0,  1,  1,  1,  1,  2,  2,  2,  2,  2};
template <typename T>
struct BIT {
 private:
  vector<T> array;
  const int n;

 public:
  BIT(int _n) : array(_n + 1, 0), n(_n) {}
  T sum(int i) {
    T s = 0;
    while (i > 0) {
      s += array[i];
      i -= i & -i;
    }
  }
  T sum(int i, int j) {
    T ret_i = sum(i - 1);
    T ret_j = sum(j);
    return ret_j - ret_i;
  }
  void add(int i, T x) {
    while (i <= n) {
      array[i] += x;
      i += i & -i;
    }
  }
};
std::vector<std::vector<long long>> comb(int n, int r) {
  std::vector<std::vector<long long>> v(n + 1,
                                        std::vector<long long>(n + 1, 0));
  for (int i = 0; i < v.size(); i++) {
    v[i][0] = 1;
    v[i][i] = 1;
  }
  for (int j = 1; j < v.size(); j++) {
    for (int k = 1; k < j; k++) {
      v[j][k] = (v[j - 1][k - 1] + v[j - 1][k]);
    }
  }
  return v;
}
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> l(n + 1), r(n + 1);
  const int MOD = 998244353;
  map<int, bool> st;
  struct st_t {
    int start;
    int end;
  };
  vector<st_t> period(n + 1);
  int pre_end = 0;
  int idx = 0;
  cin >> period[idx].start >> period[idx].end;
  for (int i = int(1); i < int(k); ++i) {
    int r, l;
    cin >> l >> r;
    if (period[i - 1].end + 1 == l) {
      period[idx].end = r;
    } else {
      idx++;
      period[idx].start = l;
      period[idx].end = r;
    }
  }
  vector<ll> dp(n + 1, 0);
  dp[1] = 1;
  for (int i = int(1); i < int(n + 1); ++i) {
    for (int i_idx = 0; i_idx < (int)idx + 1; i_idx++) {
      if (period[i_idx].start > i - 1) {
        continue;
        ;
      }
      int minus_l = max(i - period[i_idx].end, 0);
      int minus_r = i - period[i_idx].start;
      dp[i] += accumulate(&dp[minus_l], &dp[minus_r + 1], 0LL);
    }
  }
  cout << dp[n] % MOD;
  return 0;
}
