#include <bits/stdc++.h>
using namespace std;
long long dx[4] = {1, 0, -1, 0};
long long dy[4] = {0, 1, 0, -1};
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long a, b, c, d, m, n, k, x, y, maxi = 0, f = 0, mini = LLONG_MAX,
                                       sum = 0;
  string str;
  long long size = 200008;
  long long dp[size];
  for (long long i = (long long)(0); i < (long long)(size); i++) dp[i] = 0;
  cin >> n >> k;
  vector<long long> v;
  for (long long i = (long long)(0); i < (long long)(k); i++) {
    cin >> a >> b;
    for (long long i = a; i <= b; i++) {
      v.push_back(i);
    }
  }
  dp[1] = 1;
  sort((v).begin(), (v).end());
  for (long long i = 1; i <= n; i++) {
    for (long long j = (long long)(0); j < (long long)(v.size()); j++) {
      if (i + v[j] >= size) continue;
      dp[i + v[j]] += dp[i];
      dp[i + v[j]] %= 998244353;
    }
  }
  for (long long i = (long long)(0); i < (long long)(20); i++) {
  }
  cout << dp[n] << endl;
  return 0;
}
