#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int dp[200005];
vector<int> d;
int dfs(int n) {
  if (dp[n] != -1) return dp[n];
  dp[n] = 0;
  for (auto x : d) {
    if (n - x <= 0) break;
    dp[n] = (dp[n] + dfs(n - x)) % 998244353;
  }
  return dp[n];
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  memset(dp, -1, sizeof(dp));
  int n, k, i, l, r;
  cin >> n >> k;
  while (k--) {
    cin >> l >> r;
    for (i = l; i <= r; ++i) d.push_back(i);
  }
  sort(d.begin(), d.end());
  dp[1] = 1;
  dfs(n);
  cout << dp[n];
  return 0;
}
