#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(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...);
}
const long long mod = 1e9 + 7;
const long long N = 2e5 + 5;
long long i, j;
vector<long long> dp(N, 0);
void solve() {
  long long n, k;
  cin >> n >> k;
  ;
  long long second = k;
  vector<long long> s;
  while (second--) {
    long long l, r;
    cin >> l >> r;
    ;
    for (i = l; i <= r; i++) {
      s.push_back(i);
    }
  }
  dp[1] = 1;
  for (i = 2; i <= n; i++) {
    for (auto it : s) {
      long long st = i - it;
      if (st >= 1) {
        dp[i] = (dp[i] + dp[st]) % 998244353;
      }
    }
  }
  long long ans = dp[n] % 998244353;
  cout << ans << "\n";
  ;
}
int32_t main() {
  long long t;
  t = 1;
  while (t--) {
    solve();
  }
}
