#include <bits/stdc++.h>
using namespace std;
bool vowel(char che) {
  if (che == 'A' || che == 'E' || che == 'I' || che == 'O' || che == 'U' ||
      che == 'Y')
    return true;
  else
    return false;
}
const int N = 1e6 + 5;
const int mod = 998244353;
long long a[N], l[N], r[N], b[N], c[N], d, dp[N], dis, tree[N];
pair<long long, long long> p[N];
char o;
bool mark[N], h;
string s, s1;
stack<int> st;
set<long long> st1, st2;
deque<int> dq;
vector<int> vt, vs, vm;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long t = 0, n, m = 0, k = 0, f = 0, sum = 0, ans = 0, n1 = 0;
  cin >> n >> n1;
  for (int i = 0; i < n1; i++) {
    cin >> p[i].first >> p[i].second;
  }
  sort(p, p + n1);
  t = 0;
  for (int i = 0; i < n1; i++) {
    t = max(t, p[i].first);
    for (int j = t; j <= p[i].second; j++) {
      a[j] = 1;
    }
    t = max(t, p[i].second);
  }
  for (int i = 1; i <= 2e5 + 5; i++) {
    if (a[i] == 1) {
      b[m++] = i;
    }
  }
  for (int i = 0; i < m; i++) {
    dp[b[i] + 1] = 1;
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < m; j++) {
      if ((i - b[j]) > 0) dp[i] += dp[i - b[j]];
      dp[i] %= mod;
    }
  }
  cout << dp[n] << endl;
}
