#include <bits/stdc++.h>
using namespace std;
template <typename T>
istream &operator>>(istream &in, vector<T> &a) {
  for (auto &i : a) {
    in >> i;
  }
  return in;
}
template <typename T>
ostream &operator<<(ostream &out, vector<T> &a) {
  for (auto &i : a) {
    out << i << ' ';
  }
  out << '\n';
  return out;
}
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(const T &x) {
  int f = 0;
  cerr << '{';
  for (auto &i : x) cerr << (f++ ? "," : ""), __print(i);
  cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename T, typename... V>
void _print(T t, V... v) {
  __print(t);
  if (sizeof...(v)) cerr << ", ";
  _print(v...);
}
bool isVowel(char c) {
  if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u') {
    return true;
  }
  return false;
}
vector<int> all;
int dp[200005];
const int mod = 998244353;
long long int solve(int pos, int n) {
  if (pos > n) {
    return 0;
  }
  if (pos == n) {
    return 1;
  }
  if (dp[pos] != -1) return dp[pos];
  long long int ans = 0;
  for (int i : all) {
    ans = (ans + solve(pos + i, n)) % mod;
  }
  return dp[pos] = ans % mod;
}
int32_t main() {
  int n, k;
  cin >> n >> k;
  set<int> total;
  memset(dp, -1, sizeof(dp));
  for (int i = 0; i < k; i++) {
    int l, r;
    cin >> l >> r;
    for (int i = l; i <= r; i++) {
      total.insert(i);
    }
  }
  for (int i : total) {
    all.push_back(i);
  }
  cout << solve(1, n) << '\n';
}
