#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MOD = 998244353;
const int MAXN = 1e6;
ll dp[MAXN];
bool v[MAXN];
vector<int> nums;
ll solve(int n) {
  if (n <= 0) return 0;
  if (n == 1) return 1;
  if (v[n]) return dp[n];
  ll ways = 0;
  for (auto val : nums) {
    ll& new_way = dp[n - val] = solve(n - val);
    ways = (ways + new_way) % MOD;
  }
  v[n] = 1;
  dp[n] = ways;
  return dp[n];
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  for (int i = 0; i < k; i++) {
    int l, r;
    cin >> l >> r;
    for (int j = l; j <= r; j++) nums.push_back(j);
  }
  ll ans = 0;
  cout << solve(n) << "\n";
  return 0;
}
