#include <bits/stdc++.h>
using namespace std;
long long mod = 998244353;
long long dx[] = {-1, 1, 0, 0};
long long dy[] = {0, 0, 1, -1};
bool test = 0;
const long long inf = 1e18;
const long long N = 1e5 + 5;
long long n, k;
void solve() {
  cin >> n >> k;
  vector<long long> v;
  for (long long i = 1, l, r; i <= k; ++i) {
    cin >> l >> r;
    for (long long j = l; j <= r; ++j) v.emplace_back(j);
  }
  sort(v.begin(), v.end());
  vector<long long> dp(n + 1);
  dp[1] = 1;
  for (long long i = 2; i <= n; ++i)
    for (long long j = 0; j < v.size(); ++j)
      if (i >= v[j]) {
        dp[i] += dp[i - v[j]];
        dp[i] %= mod;
      }
  cout << dp[n];
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long t = 1;
  if (test) cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
