#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"); }
void __print(vector<bool> v) {
  bool first = true;
  cerr << "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      cerr << ", ";
    }
    first = false;
    __print(v[i]);
  }
  cerr << "}";
}
template <size_t N>
void __print(bitset<N> bs) {
  string res = "<";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + bs[i]);
  }
  res += '>';
  cerr << res;
}
template <typename T>
void __print(const T &x) {
  int j = 0;
  cerr << "{";
  for (auto &i : x) cerr << (j++ ? ", " : ""), __print(i);
  cerr << "}";
}
template <typename T, typename V>
void __print(const pair<T, V> &x) {
  cerr << "(";
  __print(x.first);
  cerr << ", ";
  __print(x.second);
  cerr << ")";
}
template <typename A, typename B, typename C>
void __print(const tuple<A, B, C> t) {
  cerr << "(";
  __print(get<0>(t));
  cerr << ", ";
  __print(get<1>(t));
  cerr << ", ";
  __print(get<2>(t));
  cerr << ")";
}
template <typename A, typename B, typename C, typename D>
void __print(const tuple<A, B, C, D> t) {
  cerr << "(";
  __print(get<0>(t));
  cerr << ", ";
  __print(get<1>(t));
  cerr << ", ";
  __print(get<2>(t));
  cerr << ", ";
  __print(get<3>(t));
  cerr << ")";
}
void _print() { cerr << " ]\n"; }
template <typename T, typename... V>
void _print(T t, V... v) {
  __print(t);
  if (sizeof...(v)) cerr << ", ";
  _print(v...);
}
const int M = 998244353;
const int INF = 1e9 + 5;
void init() {}
void solve() {
  long long n, k;
  cin >> n >> k;
  vector<long long> c;
  long long tl, tr;
  for (int i = (0); i < (k); ++i) {
    cin >> tl >> tr;
    for (int j = (tl); j < (tr + 1); ++j) {
      c.push_back(j);
    }
  }
  long long m = *max_element((c).begin(), (c).end());
  vector<long long> res(n + m);
  res[1] = 1;
  for (int i = (1); i < (n); ++i) {
    for (auto &j : c) {
      res[i + j] += res[i];
      res[i + j] %= M;
    }
  }
  cout << res[n] << "\n";
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.setf(ios::fixed);
  cout.precision(20);
  init();
  solve();
}
