#include <bits/stdc++.h>
using namespace std;
const int INF = 1001001001;
const long long INFL = 1e17;
const int MOD = 998244353;
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> s;
  for (int i = 0; i < k; i++) {
    int l, r;
    cin >> l >> r;
    for (int j = l; j <= r; j++) s.push_back(j);
  }
  sort(s.begin(), s.end());
  vector<long long> dp(200001, 0);
  dp[1] = 1;
  long long ans = 0;
  for (int i = 1; i < n; i++) {
    for (int j = 0; j < int(s.size()); j++) {
      int next = i + s[j];
      if (next == n)
        ans = (ans + dp[i]) % MOD;
      else if (next > n)
        break;
      else {
        dp[next] = (dp[i] + dp[next]) % MOD;
      }
    }
  }
  cout << ans << endl;
  return 0;
}
