#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MOD = 998244353;
int ok[200010];
int main() {
  int n, k;
  cin >> n >> k;
  map<int, int> mp;
  for (int i = 0; i < k; ++i) {
    int l, r;
    cin >> l >> r;
    for (int j = l; j <= r; ++j) {
      mp[j] = 1;
    }
  }
  vector<int> dp(n + 1, 0);
  dp[0] = 0;
  dp[1] = 1;
  for (int i = 1; i < n; ++i) {
    for (auto p : mp) {
      if (i + p.first > n) break;
      dp[i + p.first] += (dp[i] % MOD);
      dp[i + p.first] %= MOD;
    }
  }
  cout << dp[n] << endl;
  return 0;
}
