#include <bits/stdc++.h>
using namespace std;
template <typename T>
T gcd(T a, T b) {
  if (a % b == 0) {
    return (b);
  } else {
    return (gcd(b, a % b));
  }
}
template <typename T>
T lcm(T a, T b) {
  return a / gcd(a, b) * b;
}
int main(void) {
  long long n, k;
  cin >> n >> k;
  vector<long long> dp(n + 10, 0);
  vector<vector<long long>> l(k, vector<long long>(2));
  long long mn = 1e+7;
  for (long long i = 0; i < k; ++i) {
    cin >> l[i][0] >> l[i][1];
    mn = min(mn, l[i][0]);
  }
  dp[0] = 1;
  for (long long i = 0; i + mn < n; ++i) {
    for (auto j : l) {
      for (long long k = j[0]; k <= j[1]; ++k) {
        if (i + k < n) {
          dp[i + k] = (dp[i + k] + dp[i]) % 998244353;
        }
      }
    }
  }
  cout << dp[n - 1];
}
