#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long n, k;
  cin >> n >> k;
  vector<long long> a;
  for (long long i = (0); i < (k); i++) {
    long long x, y;
    cin >> x >> y;
    for (long long j = (x); j < (y + 1); j++) a.push_back(j);
  }
  vector<long long> dp(n, 0);
  dp[0] = 1;
  for (long long i = (0); i < (n); i++)
    for (long long j = (0); j < (a.size()); j++)
      if (i + a[j] < n) (dp[i + a[j]] += dp[i]) %= 998244353;
  cout << dp[n - 1] << endl;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  solve();
  return 0;
}
