#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long n, k;
  cin >> n >> k;
  long long dp[n + 1];
  dp[0] = 0;
  vector<pair<long long, long long>> v;
  for (long long p = 0; p < k; p++) {
    long long a, b;
    cin >> a >> b;
    v.push_back({a, b});
  }
  dp[1] = 1;
  for (long long i = 2; i <= n; i++) {
    dp[i] = dp[i - 1];
    for (long long p = 0; p < k; p++) {
      long long l = v[p].first;
      long long r = v[p].second;
      dp[i] = dp[i] + ((i >= l) ? dp[i - l] : 0) -
              ((i >= r + 1) ? dp[i - r - 1] : 0);
    }
  }
  cout << (dp[n] - dp[n - 1] + 998244353) % 998244353 << "\n";
  return 0;
}
