#include <bits/stdc++.h>
using namespace std;
long long dp[4000005], u[22];
set<long long> s;
int main() {
  long long r, g, h, i, j, x, t, y, z = 0, e, f, a, b, c, d, n, m, l, k;
  cin >> n >> k;
  for (i = 0; i < k; i++) {
    cin >> a >> b;
    for (j = a; j <= b; j++) s.insert(j);
  }
  l = s.size();
  for (auto j : s) {
    u[z++] = j;
  }
  dp[n] = 1;
  for (i = n - 1; i >= 1; i--) {
    dp[i] = 0;
    for (j = 0; j < l; j++) {
      dp[i] = (dp[i] + dp[i + u[j]]) % 998244353;
    }
  }
  cout << dp[1] % 998244353 << endl;
}
