#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e10;
const ll MOD = 998244353;
int main() {
  int ans = 0;
  int N, K;
  cin >> N >> K;
  int L, R;
  set<int> S = {};
  for (int i = 0; (i) < ((int)(K)); ++(i)) {
    cin >> L >> R;
    for (int j = L; j <= R; j++) S.insert(j);
  }
  vector<ll> DP(N + 1, 0);
  DP[1] = 1;
  for (int i = 1; i <= N; i++) {
    for (int s : S) {
      int j = i + s;
      if (j <= N) DP[j] = (DP[j] + DP[i]) % MOD;
    }
  }
  cout << DP[N] << endl;
}
