#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = LONG_LONG_MAX / 2;
const ll mod = 998244353;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
int main() {
  int N, K;
  cin >> N >> K;
  set<int> s;
  for (int i = 0; i < K; i++) {
    int l, r;
    cin >> l >> r;
    for (int j = l; j <= r; j++) {
      s.insert(j);
    }
  }
  vector<int> v(s.size());
  copy(s.begin(), s.end(), v.begin());
  vector<ll> dp(N + 1, 0);
  dp[1] = 1;
  for (int i = 1; i < N; i++) {
    for (int j : v) {
      if (i + j > N) continue;
      dp[i + j] += dp[i];
      dp[i + j] %= mod;
    }
  }
  cout << dp[N] << endl;
}
