#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
const long double PI = acos(-1);
const long double EPS = 0.0000000001;
const long long LINF = 1001002003004005006ll;
const int INF = 1001001001;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
string YES[2] = {"NO", "YES"};
string yes[2] = {"No", "Yes"};
int main() {
  long long n, k;
  cin >> n >> k;
  vector<pair<long long, long long>> seg(k);
  long long md = 998244353;
  vector<long long> csum(n + 2, 0);
  set<long long> key;
  for (long long i = 0; i < (long long)(k); i++) {
    long long a, b;
    cin >> a >> b;
    seg[i] = {a, b};
    csum[a] += 1;
    csum[b + 1] -= 1;
  }
  for (long long i = 0; i < (long long)(n + 2); i++) {
    csum[i + 1] += csum[i];
    if (0 < csum[i + 1]) key.insert(i + 1);
  }
  vector<long long> dp(n + 1, 0);
  dp[1] = 1;
  for (long long i = 1; i < (long long)(n); i++) {
    for (auto x : key) {
      if (n < i + x) break;
      dp[i + x] += dp[i];
      dp[i + x] %= md;
    }
  }
  cout << dp[n] << endl;
}
