#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long long M = 998244353;
const long long N = 2e5 + 5;
vector<long long> v;
long long dp[N], n, k;
long long get(long long n) {
  if (n <= 0) return 0;
  if (n == 1) return 1;
  if (dp[n] != -1) return dp[n];
  long long ans = 0;
  for (long long i : v) {
    ans += get(n - i);
    ans %= M;
  }
  return dp[n] = ans;
}
void solve() {
  memset(dp, -1, sizeof dp);
  cin >> n >> k;
  long long l[k], r[k];
  for (long long i = 0; i < k; i++) {
    cin >> l[i] >> r[i];
  }
  for (long long i = 0; i < k; i++) {
    for (long long j = l[i]; j <= r[i]; j++) v.push_back(j);
  }
  sort(v.rbegin(), v.rend());
  cout << get(n) << '\n';
  {};
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  long long t = 1;
  while (t--) solve();
}
