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