#include <bits/stdc++.h>
using namespace std;
constexpr auto mod = 998244353;
int dp[(200000 << 1) + 5];
vector<pair<int, int>> v;
int main() {
  int n, k;
  cin >> n >> k;
  for (int i = 1; i <= k; i++) {
    int a, b;
    cin >> a >> b;
    v.emplace_back(make_pair(a, b));
  }
  dp[1] = 1;
  dp[2] = -1;
  for (int i = 1; i <= n; i++) {
    dp[i] = (dp[i] + dp[i - 1] + mod) % mod;
    for (int j = 0; j < k; j++) {
      dp[i + v[j].first] = dp[i + v[j].first] + dp[i];
      dp[i + v[j].second + 1] = dp[i + v[j].second + 1] - dp[i];
    }
  }
  cout << dp[n] << endl;
  return 0;
}
