#include <bits/stdc++.h>
using namespace std;
const long long mxN = 1e5 + 1;
void solve() {
  long long M = 998244353;
  long long n, q;
  cin >> n >> q;
  set<long long> s;
  for (long long i = 0; i < q; i++) {
    long long l, r;
    cin >> l >> r;
    for (long long j = l; j <= r; j++) {
      s.insert(j);
    }
  }
  vector<long long> v;
  for (auto it = s.begin(); it != s.end(); it++) v.push_back(*it);
  long long dp[10000] = {0};
  dp[0] = 0;
  dp[1] = 1;
  for (long long i = 0; i < v.size(); i++)
    if (v[i] != 1) dp[v[i]] += 1;
  for (long long i = 2; i <= n; i++) {
    long long ans = 0;
    for (long long j = 0; j < v.size(); j++) {
      if (i - v[j] >= 0) ans = (ans % M + dp[i - v[j]] % M) % M;
    }
    dp[i] = ans % M;
  }
  cout << dp[n] % M << endl;
}
signed main() {
  long long t;
  solve();
}
