#include <bits/stdc++.h>
using namespace std;
const long long mod = 998244353;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, k;
  cin >> n >> k;
  vector<pair<int, int>> s;
  vector<int> dp(2 * n + 5);
  for (int i = 0; i < k; i++) {
    int l, r;
    cin >> l >> r;
    s.push_back({l, r});
  }
  dp[1] = 1;
  for (int i = 1; i <= n; i++) {
    dp[i] = (dp[i - 1] + dp[i]) % mod;
    for (int j = 0; j < k; j++) {
      int l = s[j].first, r = s[j].second;
      dp[i + l] = (dp[i] + dp[i + l]) % mod;
      dp[i + r + 1] = (dp[i + r + 1] - dp[i]) % mod;
    }
  }
  cout << dp[n] << '\n';
  return 0;
}
