#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
inline long long max3(long long a, long long b, long long c) {
  return (a) > (b) ? ((a) > (c) ? (a) : (c)) : ((b) > (c) ? (b) : (c));
}
inline long long min3(long long a, long long b, long long c) {
  return (a) < (b) ? ((a) < (c) ? (a) : (c)) : ((b) < (c) ? (b) : (c));
}
const long long int N = 200005;
void solve() {
  long long int n, m, mx, my, t = 0, k = 0, x = 0, y = 0, z = 0, a1, a2, a3, a4,
                              a5, var = 1, f = 9223372036854775807, che = 0, ex;
  cin >> n >> k;
  vector<long long int> l(k), r(k);
  vector<long long int> a;
  for (long long int(i) = 0; (i) < (k); (i)++) {
    cin >> l[i] >> r[i];
    for (int j = l[i]; j <= r[i]; j++) {
      a.push_back(j);
    }
  }
  sort(((a)).begin(), ((a)).end());
  vector<long long int> dp(n + 5, 0);
  m = a.size();
  for (long long int(i) = 0; (i) < (m); (i)++) dp[n - a[i]] = 1;
  y = n - a[0];
  for (long long int(i) = (y - 1); (i) >= (1); (i)--) {
    for (long long int(j) = 0; (j) < (m); (j)++) {
      if (dp[i + a[j]] != 0) {
        dp[i] = (dp[i] + dp[i + a[j]]) % 998244353;
      }
      if (i + a[j] >= n) break;
    }
  }
  cerr << "dp"
       << " : "
       << "[";
  for (int i = 0; i < (dp).size(); i++) cerr << dp[i] << " ";
  cerr << "]\n";
  cout << dp[1] << "\n";
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int T = 1, t = 0;
  while (t++ < T) {
    solve();
  }
  cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC
       << "ms\n";
}
