#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...);
}
long long MOD = 1e9 + 7;
long long MOD1 = 998244353;
long long gmx = 1e6 + 7;
vector<long long> fact(gmx, 1);
long long powp(long long val, long long deg) {
  if (!deg) return 1;
  if (deg & 1) return (powp(val, deg - 1) * val) % MOD;
  long long res = powp(val, deg >> 1);
  return (res * res) % MOD;
}
long long mx = 2 * 1e5 + 7;
vector<vector<long long>> adj;
vector<long long> sub;
long long n;
void dfs(long long r, long long parent) {
  sub[r] = 1;
  for (auto k : adj[r]) {
    if (k == parent) {
      continue;
    }
    dfs(k, r);
    sub[r] += sub[k];
  }
  return;
}
long long gcd(long long a, long long b) {
  if (a > b) {
    swap(a, b);
  }
  if (a == 0) {
    return b;
  }
  return gcd(a, b % a);
}
int centroid(long long u, long long p) {
  for (auto v : adj[u])
    if (v != p and sub[v] > n / 2) return centroid(v, u);
  return u;
}
int main() {
  long long n, x, m, k, i, j, o;
  cin >> n >> k;
  n += 1;
  vector<pair<long long, long long>> l;
  for (i = 0; i < k; i++) {
    cin >> j >> m;
    l.push_back(make_pair(j, m));
  }
  vector<long long> dp(n), pre(n);
  dp[1] = 1;
  pre[1] = 1;
  for (i = 2; i < n; i++) {
    for (j = 0; j < k; j++) {
      if ((i > l[j].first) && (l[j].first != l[j].second)) {
        dp[i] += pre[i - l[j].first] - pre[i - min(l[j].second, i - 1) - 1];
        dp[i] %= MOD1;
      }
      if ((i >= l[j].second) && (l[j].first == l[j].second)) {
        dp[i] += dp[i - l[j].second];
        dp[i] %= MOD1;
      }
    }
    pre[i] = dp[i] + pre[i - 1];
    pre[i] %= MOD1;
  }
  if (dp[n - 1] > 0) {
    cout << dp[n - 1];
  } else {
    cout << MOD1 + dp[n - 1];
  }
}
