#include <bits/stdc++.h>
#pragma GCC optimize(3)
using namespace std;
int n, k;
vector<int> v;
long long dp[200010];
int main() {
  cin >> n >> k;
  for (int i = 0; i < k; i++) {
    int a, b;
    cin >> a >> b;
    for (int j = a; j <= b; j++) v.push_back(j);
  }
  sort(v.begin(), v.end());
  unique(v.begin(), v.end());
  memset(dp, 0, sizeof(dp));
  dp[1] = 1LL;
  for (int i = 2; i <= n; i++) {
    for (int j = 0; j < v.size(); j++) {
      if (v[j] >= i) break;
      dp[i] += dp[i - v[j]];
      dp[i] %= 998244353;
    }
  }
  cout << dp[n] << endl;
  return 0;
}
