#include <bits/stdc++.h>
using namespace std;
template <typename T>
istream &operator>>(istream &is, vector<T> &v) {
  for (auto &it : v) is >> it;
  return is;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  os << '{';
  string sep = "";
  for (const auto &x : v) os << sep << x, sep = ", ";
  return os << '}';
}
template <typename A, typename B>
ostream &operator<<(ostream &os, const pair<A, B> &p) {
  return os << '(' << p.first << ", " << p.second << ')';
}
void dbg_out() { cerr << " end.\n"; }
template <typename Head, typename... Tail>
void dbg_out(Head H, Tail... T) {
  cerr << ' ' << H;
  dbg_out(T...);
}
const int N = 2e5 + 5;
const int mod = 998244353;
int dp[N];
void solve() {
  int n, k;
  cin >> n >> k;
  vector<long long> L(k), R(k);
  vector<long long> st;
  for (int i = 0; i < k; ++i) {
    cin >> L[i] >> R[i];
    for (int j = L[i]; j <= R[i]; ++j) st.push_back(j);
  }
  sort(st.begin(), st.end());
  memset(dp, 0, sizeof dp);
  dp[1] = 1;
  for (int i = 1; i <= n; ++i) {
    for (int x : st) {
      if (i + x > n) break;
      dp[i + x] += dp[i];
      dp[i + x] %= mod;
    }
  }
  cout << dp[n] << "\n";
}
int main() {
  cin.tie(0), ios::sync_with_stdio(0);
  solve();
  return 0;
}
