#include <bits/stdc++.h>
using namespace std;
long long min(long long a, long long b) {
  if (a < b)
    return a;
  else
    return b;
}
long long max(long long a, long long b) {
  if (a < b)
    return b;
  else
    return a;
}
long long min3(long long a, long long b, long long c) {
  return min(a, min(b, c));
}
long long max3(long long a, long long b, long long c) {
  return max(a, max(b, c));
}
long long ceil1(long long x, long long y) {
  if (x % y)
    return (x + y) / y;
  else
    return x / y;
}
long long NC = 100;
long long N = 998244353;
const long long second = 1e5 + 7;
long long mod(long long n);
long long gcd(long long a, long long b);
long long modM(long long n, long long m);
long long modA(long long n, long long m);
long long modS(long long n, long long m);
long long power(long long a, long long b);
void ipgraph(long long n, long long m);
vector<vector<long long>> v;
vector<bool> vis;
void solve() {
  long long n, k;
  cin >> n >> k;
  vector<long long> b(n + 1, 0);
  vector<long long> a;
  while (k--) {
    long long x, y;
    cin >> x >> y;
    b[y]++;
    b[x]--;
    if (x == y) a.push_back(x);
  }
  long long f = 0;
  for (long long i = n; i > 0; i--) {
    if (b[i] > 0) {
      a.push_back(i), f = 1;
      continue;
    }
    if (b[i] < 0) {
      a.push_back(i), f = 0;
      continue;
    }
    if (f) {
      a.push_back(i);
      continue;
    }
  }
  sort(a.begin(), a.end());
  vector<long long> dp(n + 1, 0);
  dp[1] = 1;
  for (long long i = 2; i < n + 1; i++) {
    for (long long j = 0; j < a.size(); j++) {
      if (i > a[j])
        dp[i] += dp[i - a[j]];
      else
        break;
    }
  }
  cout << dp[n] % N;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long t;
  t = 1;
  while (t--) solve();
  cerr << endl
       << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC
       << "ms\n";
  return 0;
}
void ipgraph(long long n, long long m) {
  v.assign(n, {});
  vis.assign(n, 0);
  long long x, y;
  for (long long i = 0; i < m; i++) {
    cin >> x >> y;
    x--, y--;
    v[y].push_back(x);
    v[x].push_back(y);
  }
}
long long gcd(long long a, long long b) {
  if (b > a) return gcd(b, a);
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long power(long long a, long long b) {
  if (b == 0) return 1;
  long long c = power(a, b / 2);
  if (b % 2 == 0)
    return modM(c, c);
  else
    return modM(modM(c, c), a);
}
long long mod(long long n) { return (n % N + N) % N; }
long long modM(long long n, long long m) { return ((n % N * m % N) + N) % N; }
long long modA(long long n, long long m) { return ((n % N + m % N) + N) % N; }
long long modS(long long n, long long m) { return ((n % N - m % N) + N) % N; }
