#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll MOD = 998244353;
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> l(k, 0), r(k, 0);
  for (int(i) = 0; (i) < (k); ++(i)) {
    cin >> l[i] >> r[i];
    l[i]--;
    r[i]--;
  }
  vector<ll> dp(n + 1, 0);
  vector<ll> cnt(n + 1, 0);
  dp[0] = 1;
  for (int i = 1; i < n; ++i) {
    for (int j = 0; j < k; ++j) {
      int ll = i - l[j];
      int rr = i - r[j];
      if (ll <= 0) continue;
      if (rr < 0) rr = 0;
      for (int k = rr; k <= ll; ++k) {
        if (k < 0) continue;
        dp[i] += dp[k];
        dp[i] %= MOD;
      }
    }
  }
  cout << (dp[n - 1] % MOD) << endl;
}
