#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
const long long l_INF = 1010101010101010;
const int INF = 1010101010;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};
using vi = vector<int>;
using vll = vector<long long>;
using vvi = vector<vi>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
const long long mod = 998244353;
int main() {
  int n, k;
  cin >> n >> k;
  vi l(k), r(k);
  long long dp[201010];
  for (int i = 0; i < k; i++) {
    cin >> l[i] >> r[i];
  }
  set<int> judge;
  for (int i = 0; i < 201010; i++) {
    for (int j = 0; j < k; j++) {
      if (i >= l[j] && i <= r[j] && !(judge.count(i))) judge.insert(i);
    }
  }
  dp[0] = 1;
  for (int i = 0; i < n + 1; i++) {
    if (i == 0) continue;
    for (int j = 1; j <= i; j++)
      if (judge.count(j)) dp[i] += dp[i - j];
  }
  dp[n - 1] %= mod;
  cout << dp[n - 1] << endl;
}
