#include <bits/stdc++.h>
using namespace std;
using G = vector<vector<int>>;
using M = map<int, int>;
using P = pair<int, int>;
using PQ = priority_queue<int>;
using PQG = priority_queue<int, vector<int>, greater<int>>;
using V = vector<int>;
using ll = long long;
using edge = struct {
  int to;
  int cost;
};
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
const int INF = 1e9;
const int MOD = 998244353;
const ll LINF = 1e18;
const int MAXN = 200010;
int dp[MAXN];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int n, k;
  cin >> n >> k;
  set<int> s;
  int l, r;
  vector<int> tmp(n + 5, 0), ss(n + 5, 0);
  for (int i = 0; i < k; i++) {
    cin >> l >> r;
    l--;
    r--;
    tmp[l]++;
    tmp[r + 1]--;
  }
  for (int i = 0; i < n + 1; i++) {
    ss[i + 1] = ss[i] + tmp[i];
  }
  for (int i = 0; i < n + 1; i++) {
    if (ss[i] > 0) s.insert(i);
  }
  dp[0] = 1;
  for (int i = 1; i < n; i++) {
    for (auto x : s) {
      if (i - x < 0) break;
      if (dp[i - x] == 0) continue;
      dp[i] += dp[i - x];
      dp[i] %= MOD;
    }
  };
  cout << (dp[n - 1]) << "\n";
  return 0;
}
