#include <bits/stdc++.h>
using namespace std;
const long long int INF = 1LL << 60;
const int dx[4] = {1, 0, -1, 0};
struct edge {
  long long int from, to, cost;
};
long long int gcd(long long int a, long long int b) {
  if (a % b == 0)
    return (b);
  else
    return (gcd(b, a % b));
}
int main() {
  long long int n, k;
  cin >> n >> k;
  long long int dp[n + 1];
  fill(dp, dp + n + 1, 0);
  dp[1] = 1;
  bool x[n + 1];
  fill(x, x + n + 1, false);
  vector<long long int> v;
  for (long long int i = 0; i < k; i++) {
    long long int l, r;
    cin >> l >> r;
    for (long long int i = l; i <= r; i++) {
      if (!x[i]) {
        x[i] = true;
        v.push_back(i);
      }
    }
  }
  for (long long int j = 1; j <= n; j++) {
    for (long long int i = 0; i < v.size(); i++) {
      if (j + v[i] <= n) {
        dp[j + v[i]] += dp[j];
        dp[j + v[i]] %= 998244353;
      }
    }
  }
  cout << dp[n] % 998244353 << endl;
  return 0;
}
