#include <bits/stdc++.h>
using namespace std;
const long long MX = 1e6;
const long long inf = 1e9 + 5;
const long long mod = 1e9 + 7;
long long a[MX];
long long vis[MX];
vector<long long> d;
long long dfs(long long v) {
  if (v <= 0) return 0;
  vis[v] = 1;
  for (auto dd : d) {
    if (v - dd >= 0) {
      if (vis[v - dd] == 0) {
        a[v - dd] = dfs(v - dd);
        vis[v - dd] = 1;
      }
      a[v] += a[v - dd];
    }
  }
  return a[v] % 998244353;
}
signed main() {
  long long n, k;
  cin >> n >> k;
  a[0] = 0;
  a[1] = 1;
  vector<long long> b(n + 5);
  for (long long i = (0); i < (k); ++i) {
    long long x, y;
    cin >> x >> y;
    b[x] = 1;
    b[y + 1] = -1;
  }
  for (long long i = (1); i < (n); ++i) {
    b[i] = b[i - 1] + b[i];
  }
  for (long long i = (0); i < (n); ++i) {
    if (b[i] >= 1) {
      b[i] = 1;
      d.push_back(i);
    } else
      b[i] = 0;
  }
  cout << dfs(n) << endl;
  return 0;
}
