#include <bits/stdc++.h>
using namespace std;
const long long m = 998244353;
int main() {
  long long n, k;
  cin >> n >> k;
  set<long long> s;
  for (int i = 1; i <= k; i++) {
    long long a, b;
    cin >> a >> b;
    for (int j = a; j <= b; j++) s.insert(j);
  }
  vector<long long> dp(n + 1, 0);
  dp[1] = 1;
  for (long long i = 2; i <= n; i++) {
    for (long long j = i - 1; j >= 1; j--) {
      if (s.find(i - j) != s.end()) {
        dp[i] += dp[j];
        dp[i] %= m;
      }
    }
  }
  cout << dp[n];
  return 0;
}
