#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(0);
  long long t, ch, i, curr, p = 1, x, y, weight, j, k = 0, n, m = 1, ch1,
                            ans = 0;
  long long a, b;
  int fl, fl1, fl2, fl3;
  string s;
  long long f, size_f, size_s, weight1, weight2;
  long long sum, k_min, k_max, s1;
  long long da, db;
  cin >> n >> k;
  set<long long> sets;
  long long l, r;
  long long* dp = new long long[n + 5];
  for (i = 0; i < n + 2; i++) dp[i] = 0;
  dp[0] = 1;
  for (i = 0; i < k; i++) {
    cin >> l >> r;
    for (j = l; j <= r; j++) sets.insert(j);
  }
  for (i = 0; i < n; i++) {
    for (auto it : sets)
      if (i + it < n)
        dp[i + it] = (dp[i + it] + dp[i]) % 998244353;
      else
        break;
  }
  cout << dp[n - 1];
  return 0;
}
