#include <bits/stdc++.h>
using namespace std;
const long long mod = 998244353;
template <typename T>
void print(T t) {
  for (const auto& e : t) cout << e << " ";
  cout << endl;
}
long long nod(long long n) { return floor(log10(n) + 1); }
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n, k, l, r;
  cin >> n >> k;
  set<long long> s;
  vector<long long> a;
  while (k--) {
    cin >> l >> r;
    for (long long i = l; i <= r; i++) {
      s.insert(i);
    }
  }
  for (auto x : s) {
    a.push_back(x);
  }
  long long dp[n + 1];
  for (long long i = 2; i <= n; i++) dp[i] = 0;
  dp[1] = 1;
  for (long long i = 2; i <= n; i++) {
    for (auto x : a) {
      if (i > x) {
        dp[i] = (dp[i] % mod + dp[i - x] % mod) % mod;
      } else {
        break;
      }
    }
  }
  cout << dp[n] << endl;
  return 0;
}
