#include <bits/stdc++.h>
using namespace std;
const long long mod = 998244353;
signed main() {
  long long n, m;
  cin >> n >> m;
  vector<long long> dp(n + 1);
  vector<long long> prefix(n + 1);
  prefix[0] = 0;
  prefix[1] = 1;
  dp[0] = 0;
  dp[1] = 1;
  vector<pair<long long, long long> > steps;
  for (int i = 0; i < m; i++) {
    long long l, m;
    cin >> l >> m;
    steps.push_back({l, m});
  }
  for (int i = 2; i <= n; i++) {
    dp[i] = 0;
    for (auto it : steps) {
      if ((i - it.first) <= 0)
        continue;
      else if ((i - it.second) > 0) {
        int first = max(i - it.first, i - it.second - 1);
        int second = min(i - it.first, i - it.second - 1);
        dp[i] = (dp[i] + prefix[first] - prefix[second]) % mod;
      } else if ((i - it.first) > 0 && (i - it.second) <= 0) {
        dp[i] = (dp[i] + prefix[i - it.first]) % mod;
      }
    }
    prefix[i] = (prefix[i - 1] + dp[i]) % mod;
  }
  cout << dp[n];
  return 0;
}
