#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <class T1, class T2>
ostream& operator<<(ostream& os, const pair<T1, T2>& v) {
  os << "(" << v.first << ", " << v.second << ")";
  return os;
}
template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
  os << "{";
  for (int i = 0; i < v.size(); i++) {
    if (i) os << ", ";
    os << v[i];
  }
  os << "}";
  return os;
}
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> l(n);
  vector<int> r(n);
  for (int i = 0; i < k; i++) {
    cin >> l[i] >> r[i];
  }
  vector<ll> f(n, 0);
  f[0] = 1;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < k; j++) {
      for (int s = l[j]; s <= r[j]; s++) {
        if (i + s >= n) continue;
        f[i + s] += f[i];
        f[i + s] %= 998244353;
      }
    }
  }
  cout << f[n - 1] << endl;
  return 0;
}
