#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("-Ofast")
#pragma GCC optimize("trapv")
int power(long long x, long long y) {
  if (y == 0) return 1;
  long long p = power(x, y / 2);
  p = (p * p);
  return (y % 2 == 0) ? p : (x * p);
}
const long long N = (long long)(2e5 + 1);
const long long N2 = (long long)(1e6 + 1);
const long long INF = (long long)(2e18);
long long dp[N];
set<long long> s;
vector<long long> v;
void solve() {
  long long MOD = 998244353;
  long long n, k;
  cin >> n >> k;
  for (long long i = 1; i <= k; i++) {
    long long x, y;
    cin >> x >> y;
    for (long long j = x; j <= y; j++) {
      if (s.find(j) == s.end()) {
        v.push_back(j);
        s.insert(j);
      }
    }
  }
  dp[1] = 1;
  for (long long i = 1; i <= n; i++) {
    for (auto it : v) {
      if (i - it > 0) {
        dp[i] += dp[i - it];
        dp[i] %= MOD;
      }
    }
  }
  cout << dp[n];
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
