#include <bits/stdc++.h>
using namespace std;
const long long int mod = 998244353;
inline long long int mul(long long int a, long long int b) {
  return (a * 1ll * b) % mod;
}
inline long long int sub(long long int a, long long int b) {
  long long int c = a - b;
  if (c < 0) c += mod;
  return c;
}
inline long long int add(long long int a, long long int b) {
  long long int c = a + b;
  if (c >= mod) c -= mod;
  return c;
}
inline long long int max(long long int a, long long int b) {
  return a > b ? a : b;
}
inline long long int min(long long int a, long long int b) {
  return a < b ? a : b;
}
inline long long int ceil(long long int a, long long int b) {
  return (a % b == 0) ? (a / b) : (a / b + 1);
}
template <class T>
ostream &operator<<(ostream &os, vector<T> V) {
  for (auto v : V) os << v << "  ";
  return os;
}
template <class T>
ostream &operator<<(ostream &os, set<T> S) {
  os << "{ ";
  for (auto s : S) os << s << " ";
  return os << "}";
}
template <class L, class R>
ostream &operator<<(ostream &os, pair<L, R> P) {
  return os << "(" << P.first << "," << P.second << ")";
}
template <class L, class R>
ostream &operator<<(ostream &os, map<L, R> M) {
  os << "{ ";
  for (auto m : M) os << "(" << m.first << ":" << m.second << ") ";
  return os << "}";
}
struct comp {
  template <class T1, class T2, class T3, class T4>
  bool operator()(const pair<T1, T2> &p1, const pair<T3, T4> &p2) {
    return p1.first < p2.first;
  }
};
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int n, k;
  cin >> n >> k;
  set<long long int> s;
  for (long long int i = 0; i < k; i++) {
    long long int l, r;
    cin >> l >> r;
    for (long long int j = l; j <= r; j++) {
      s.insert(j);
    }
  }
  vector<long long int> dp(n + 1, 0);
  dp[1] = 1;
  for (long long int i = 2; i <= n; i++) {
    for (auto j : s) {
      if ((i - j) >= 0) {
        dp[i] = add(dp[i], dp[i - j]);
      }
    }
  }
  cout << dp[n] << "\n";
}
