#include <bits/stdc++.h>
using namespace std;
constexpr int MOD = 998244353;
int dp[200001];
bool checked[200001];
int solve(int n, const vector<int> &S) {
  if (checked[n]) return dp[n];
  int ans = 0;
  for (auto itr = S.begin(); itr != S.end(); ++itr) {
    int temp = n - *itr;
    if (temp <= 0) break;
    ans = (ans + solve(temp, S)) % MOD;
  }
  checked[n] = true;
  return dp[n] = ans;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, k;
  cin >> n >> k;
  vector<int> S;
  for (long long i = 0; i < k; ++i) {
    int l, r;
    cin >> l >> r;
    for (int j = l; j <= r; ++j) S.push_back(j);
  }
  sort(S.begin(), S.end());
  checked[1] = true;
  dp[1] = 1;
  cout << solve(n, S) << endl;
  return 0;
}
