#include <bits/stdc++.h>
using namespace std;
using lli = long long int;
const int MOD = 1000000007;
const int MOD1 = 998244353;
const int maxn = 100010;
const int lim = (int)1e9;
lli dp[40 * maxn];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n = 0, k = 0, x = 0, y = 0;
  cin >> n >> k;
  vector<pair<int, int> > vp;
  for (int i = 0; i < k; ++i) {
    cin >> x >> y;
    vp.emplace_back(x, y);
  }
  dp[0] = 1;
  for (int i = 1; i < n; ++i) {
    for (int j = 0; j < k; ++j) {
      if (i - vp[j].first >= 0) dp[i] = (dp[i] + dp[i - vp[j].first]) % MOD1;
      if (i - vp[j].second >= 1)
        dp[i] = (dp[i] - dp[i - vp[j].second - 1]) % MOD1;
    }
    dp[i] = (dp[i] + dp[i - 1]) % MOD1;
  }
  if (dp[n - 1] < 0ll) dp[n - 1] += MOD1;
  if (dp[n - 2] < 0ll) dp[n - 2] += MOD1;
  cout << (dp[n - 1] - dp[n - 2]) % MOD1 << endl;
}
