#include <bits/stdc++.h>
using namespace std;
long long p = 998244353;
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long t, n, i, j, k, l, r;
  cin >> n >> k;
  set<long long> s;
  for (i = 1; i <= k; i++) {
    cin >> l >> r;
    for (j = l; j <= r; j++) s.insert(j);
  }
  long long dp[n + 1];
  memset(dp, 0, sizeof(dp));
  dp[0] = 0;
  dp[1] = 1;
  for (i = 2; i <= n; i++) {
    for (auto it = s.begin(); it != s.end(); it++) {
      j = *it;
      if (j <= i)
        dp[i] = (dp[i] + dp[i - j]) % p;
      else
        break;
    }
  }
  cout << dp[n] % p;
}
