#include <bits/stdc++.h>
using namespace std;
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
T gcd(T a, T b) {
  return b ? gcd(b, a % b) : a;
}
template <class T>
T lcm(T a, T b) {
  return a / gcd(a, b) * b;
}
const int INF = 1001001001;
const long long LINF = 1001002003004005006ll;
const long long MOD = 998244353;
int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n, k;
  cin >> n >> k;
  vector<int> s;
  for (int i = 0; i < (k); ++i) {
    int l, r;
    cin >> l >> r;
    for (int d = l; d <= r; d++) {
      s.push_back(d);
    }
  }
  vector<long long> dp(n);
  dp[0] = 1;
  for (int i = 0; i < (n - 1); ++i) {
    for (int d : s) {
      if (i + 1 >= d) {
        dp[i + 1] += dp[i + 1 - d];
        dp[i + 1] %= MOD;
      }
    }
  }
  cout << dp[n - 1] << endl;
  return 0;
}
