#include <bits/stdc++.h>
using namespace std;
const long long MOD = 998244353;
int main() {
  int N, K;
  cin >> N >> K;
  vector<bool> LR(N + 1, false);
  vector<int> S;
  vector<long long> DP(N, 0);
  for (int i = 0; i < K; ++i) {
    int l, r;
    cin >> l >> r;
    if (l > r) swap(l, r);
    for (int i = l; i <= r; ++i) {
      LR[i] = true;
    }
  }
  for (int i = 1; i <= N; ++i)
    if (LR[i]) S.push_back(i);
  DP[0] = 1;
  for (int i = 1; i < N; ++i) {
    for (auto v : S) {
      if (i - v >= 0) DP[i] = (DP[i] + DP[i - v]) % MOD;
    }
  }
  cout << DP[N - 1] << endl;
}
