#include <bits/stdc++.h>
using namespace std;
const int dx[8] = {-1, -1, -1, 0, 1, 1, 1, 0};
const int dy[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
const int MAX = 2 * 1000 * 100 + 10;
const long long INF = 1e18;
const int MOD = 998244353;
vector<long long> jumps;
long long ar[MAX], dp[MAX], n, k;
long long sol(long long pos) {
  if (!pos) return 1;
  long long &ans = dp[pos];
  if (ans != -1) return ans;
  ans = 0;
  for (long long i : jumps) {
    if (i > pos) break;
    ans += sol(pos - i);
    if (ans >= MOD) ans %= MOD;
  }
  return ans;
}
void sol() {
  cin >> n >> k;
  for (long long i = 0; i < k; i++) {
    long long l, r;
    cin >> l >> r;
    ar[l]++, ar[r + 1]--;
  }
  for (long long i = 1; i < MAX; i++) ar[i] += ar[i - 1];
  for (long long i = 0; i < MAX; i++)
    if (ar[i]) jumps.push_back(i);
  memset(dp, -1, sizeof(dp));
  cout << sol(n - 1) << '\n';
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  { sol(); }
}
