#include <bits/stdc++.h>
using namespace std;
template <typename tp>
void read(tp &x) {
  cin >> x;
}
template <typename tp, typename... Args>
void read(tp &x, Args &...args) {
  read(x);
  read(args...);
}
const int mxN = (int)1e5, INF = (int)1e9, MOD = 998244353;
bool comp(pair<int, int> &a, pair<int, int> &b) {
  if (a.first == b.first) return a.second < b.second;
  return a.first < b.first;
}
void solve() {
  int n, k;
  read(n, k);
  vector<pair<int, int>> segm(k);
  for (int i = 0; i < k; i++) read(segm[i].first, segm[i].second);
  sort((segm).begin(), (segm).end(), comp);
  vector<pair<int, int>> S;
  for (int i = 0; i < k; i++) {
    if (S.empty()) {
      S.push_back(segm[i]);
      continue;
    }
    pair<int, int> a = S.back(), b = segm[i];
    if (a.first == b.first)
      S.back() = b;
    else if (b.first <= a.second)
      S.back().second = b.second;
    else
      S.push_back(b);
  }
  vector<int> dp(n + 1);
  dp[1] = 1;
  for (int i = 2; i <= n; i++) {
    dp[i] = 0;
    for (int j = 0; j < (int)(S.size()); j++) {
      for (int l = S[j].first; l <= S[j].second; l++) {
        if (i - l <= 0) break;
        dp[i] = (dp[i] + dp[i - l]) % MOD;
      }
    }
  }
  cout << dp[n] << '\n';
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int test = 1;
  while (test--) solve();
  return 0;
}
