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