#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vii = vector<vi>;
using vs = vector<string>;
using pii = pair<int, int>;
using Graph = vector<vector<int>>;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
vector<long long> dp;
int n, k;
vi to;
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 (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
bool comp(pair<int, pair<int, int>> a, pair<int, pair<int, int>> b) {
  return a.first <= b.first;
}
long long dfs(int p) {
  if (dp[p] != 0) return dp[p];
  for (int i = 0; i < (int)(to.size()); ++i) {
    if (p + to[i] > n) break;
    if (p + to[i] == n) {
      dp[p]++;
      continue;
    }
    dp[p] += dfs(p + to[i]);
    dp[p] %= 998244353;
  }
  return dp[p] %= 998244353;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> k;
  dp = vector<long long>(n + 1, 0);
  dp[n] = 1;
  vector<bool> f = vector<bool>(n + 1, false);
  for (int i = 0; i < (int)(k); ++i) {
    int l, r;
    cin >> l >> r;
    for (int j = (int)(l); j < (int)(r + 1); ++j) {
      f[j] = true;
    }
  }
  for (int i = 1; i <= (int)(n); ++i) {
    if (f[i] == true) {
      to.push_back(i);
    }
  }
  cout << dfs(1) << endl;
}
