#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
void err(istream_iterator<string> it) {}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " = " << a << endl;
  err(++it, args...);
}
template <class T>
void umin(T &a, T b) {
  a = min(a, b);
}
template <class T>
void umax(T &a, T b) {
  a = max(a, b);
}
const int dx[] = {1, 0, -1, 0, -1, -1, 1, 1};
const int dy[] = {0, 1, 0, -1, -1, 1, -1, 1};
const int inf = 1e9, mod = 998244353, N = 2e5 + 5;
int dp[N];
void solve() {
  int n, k;
  cin >> n >> k;
  int l[k], r[k];
  --n;
  vector<int> v;
  for (int i = 0; i < k; ++i) {
    cin >> l[i] >> r[i];
    for (int j = l[i]; j <= r[i]; j++) {
      v.push_back(j);
    }
  }
  sort(v.begin(), v.end());
  dp[0] = 1;
  for (int i = 1; i <= n; ++i) {
    for (int j = 0; j < (int)((v).size()); ++j) {
      if (i - v[j] >= 0) {
        dp[i] += dp[i - v[j]];
        dp[i] %= mod;
      }
    }
  }
  cout << dp[n];
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int T = 1;
  while (T--) solve();
}
