#include <bits/stdc++.h>
using namespace std;
void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }
template <typename T, typename V>
void __print(const pair<T, V> &x) {
  cerr << '{';
  __print(x.first);
  cerr << ',';
  __print(x.second);
  cerr << '}';
}
template <typename T>
void __print(vector<vector<T>> x) {
  cerr << "\n{";
  int f = x.size();
  for (int i = 0; i < f; i++) {
    cerr << "(";
    int g = x[i].size();
    for (auto j : x[i]) {
      cerr << j;
      (--g != 0) ? cerr << "," : cerr << "";
    }
    cerr << ")\n";
  }
  cerr << "}";
}
template <typename T>
void __print(const T &x) {
  int f = 0;
  cerr << '{';
  for (auto &i : x) cerr << (f++ ? "," : ""), __print(i);
  cerr << "}";
}
void __print(vector<bool> x) {
  cerr << "{";
  int f = x.size();
  for (auto i : x) {
    cerr << i;
    (--f != 0) ? cerr << "," : cerr << "";
  }
  cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename T, typename... V>
void _print(T t, V... v) {
  __print(t);
  if (sizeof...(v)) cerr << ", ";
  _print(v...);
}
template <typename... T>
void read(T &...args) {
  ((cin >> args), ...);
}
template <typename... T>
void writ(T &&...args) {
  ((cout << args << " "), ...);
}
template <class OutputIterator, class T>
OutputIterator iota_rng(OutputIterator first, T low, T high) {
  return std::generate_n(first, high - low,
                         [&, value = low]() mutable { return value++; });
}
int n, k;
set<int> mvs;
vector<long long> dp;
long long memo(int g) {
  if (g <= 0) return 0;
  if (dp[g] != -1) return dp[g];
  long long temp = 0;
  for (auto i : mvs) {
    if (i <= g) {
      temp = (temp + memo(g - i)) % (long long)998244353;
    }
  }
  return dp[g] = (temp % (long long)998244353);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> k;
  for (int i = 0; i < k; i++) {
    int x, y;
    cin >> x >> y;
    iota_rng(std::inserter(mvs, mvs.begin()), x, y);
  }
  dp.resize(n + 1, -1);
  dp[0] = 0;
  dp[1] = 1;
  cout << memo(n) << endl;
  return 0;
}
