#include <bits/stdc++.h>
using namespace std;
template <typename T>
string join(const vector<T>& v, string del = ", ") {
  stringstream s;
  for (auto x : v) s << del << x;
  return s.str().substr(del.size());
}
template <typename T>
ostream& operator<<(ostream& o, const vector<T>& v) {
  if (v.size()) o << "[" << join(v) << "]";
  return o;
}
template <typename T>
ostream& operator<<(ostream& o, const vector<vector<T> >& vv) {
  int l = vv.size();
  if (l) {
    o << endl;
    for (int i = (0); i < (int)(l); i++)
      o << (i == 0 ? "[ " : ",\n  ") << vv[i] << (i == l - 1 ? " ]" : "");
  }
  return o;
}
template <typename T1, typename T2>
ostream& operator<<(ostream& o, const pair<T1, T2>& p) {
  return o << "(" << p.first << ", " << p.second << ")";
}
inline void _debug() { cerr << endl; }
template <class First, class... Rest>
void _debug(const First& first, const Rest&... rest) {
  cerr << first << " ";
  _debug(rest...);
}
const double PI = (1 * acos(0.0));
const double EPS = 1e-9;
const int INF = 0x3f3f3f3f;
const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
const long long mod = 1e9 + 7;
inline void finput(string filename) { freopen(filename.c_str(), "r", stdin); }
int main() {
  ios_base::sync_with_stdio(0);
  int n, k;
  cin >> n >> k;
  set<int> s;
  for (int i = (0); i < (int)(k); i++) {
    int l, r;
    cin >> l >> r;
    for (int x = (l); x < (int)(r + 1); x++) s.insert(x);
  }
  vector<long long> dp(n);
  dp[0] = 1ll;
  for (int i = (1); i < (int)(n); i++)
    for (auto x : s) {
      if (i - x >= 0) dp[i] += dp[i - x];
      dp[i] %= 998244353ll;
    }
  cout << dp[n - 1] << endl;
  return 0;
}
