#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
const long long INF = 1LL << 60;
long long MOD = 1000000007;
template <typename T>
void remove(std::vector<T>& vector, unsigned int index) {
  vector.erase(vector.begin() + index);
}
int gcd(int a, int b) {
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}
long long lcm(int a, int b) { return (long long)a * b / gcd(a, b); }
long long GCD(long long a, long long b) { return b ? GCD(b, a % b) : a; }
long long dp[200100];
int main() {
  int N, K;
  cin >> N >> K;
  vector<int> S;
  for (int i = 0; i < K; i++) {
    int l, r;
    cin >> l >> r;
    for (int j = l; j <= r; j++) {
      S.push_back(j);
    }
  }
  dp[1] = 1;
  sort(S.begin(), S.end());
  for (int i = 1; i < N; i++) {
    if (dp[i] == 0) continue;
    for (int j = 0; j < S.size(); j++) {
      if (i + S[j] <= N)
        dp[i + S[j]] = (dp[i + S[j]] + dp[i]) % 998244353;
      else
        break;
    }
  }
  cout << dp[N] << endl;
}
