#include <bits/stdc++.h>
using namespace std;
set<int> s;
long long dp[200010];
long long mod = 998244353;
void dynamic(long long n) {
  cout << "dp : " << n << endl;
  if (dp[n] != 0) {
    return;
  }
  for (auto x : s) {
    if (n == x) {
      dp[n]++;
      dp[n] = dp[n] % mod;
      return;
    } else if (n - x < 0) {
      break;
    } else {
      if (dp[n - x] == 0) {
        dynamic(n - x);
      }
      dp[n] += dp[n - x];
      dp[n] = dp[n] % mod;
    }
  }
}
int main(void) {
  long long n, k, l, r;
  set<int> be, en;
  cin >> n >> k;
  for (int i = 0; i < k; i++) {
    cin >> l >> r;
    be.insert(l);
    en.insert(r);
  }
  for (int i = 1; i <= n; i++) {
    dp[i] = 0;
  }
  auto be_itr = be.begin();
  auto en_itr = en.begin();
  for (int i = 1; i <= n; i++) {
    if (i < *be_itr) {
      continue;
    } else if (i <= *en_itr) {
      s.insert(i);
    } else {
      be_itr++;
      en_itr++;
      if (i == *be_itr) {
        s.insert(i);
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    for (auto x : s) {
      if (x > i) {
        break;
      } else if (x == i) {
        dp[i]++;
        dp[i] %= mod;
      } else {
        dp[i] += dp[i - x];
        dp[i] %= mod;
      }
    }
  }
  cout << dp[n - 1] << endl;
}
