#include <bits/stdc++.h>
using namespace std;
long long p = 998244353;
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long t, n, i, j, k, l, r, l1;
  cin >> n >> k;
  vector<pair<long long, long long> > v;
  for (i = 1; i <= k; i++) {
    cin >> l >> r;
    v.push_back({l, r});
  }
  long long dp[n + 1];
  memset(dp, 0, sizeof(dp));
  dp[0] = 0;
  dp[1] = 1;
  long long dp1[n + 1];
  dp[0] = 0;
  dp[1] = 1;
  dp1[0] = 0;
  dp1[1] = 1;
  for (i = 2; i <= n; i++) {
    for (j = 0; j < v.size(); j++) {
      l = v[j].first, k = v[j].second;
      k = min(k, i - 1);
      if (l <= k) {
        l1 = ((dp1[i - l] - dp1[i - k - 1]) % p);
        dp[i] = (dp[i] + l1) % p;
      }
    }
    dp1[i] = (dp[i] + dp1[i - 1]) % p;
  }
  cout << dp[n] % p;
}
