#include <bits/stdc++.h>
using namespace std;
long long dx[8] = {-1, 0, 0, 1, -1, -1, 1, 1};
long long dy[8] = {0, 1, -1, 0, -1, 1, -1, 1};
double PI = acos(-1);
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  long long n, k;
  cin >> n >> k;
  vector<long long> v;
  for (long long i = 0; i < k; i++) {
    long long l, r;
    cin >> l >> r;
    for (long long j = l; j <= r; j++) v.push_back(j);
  }
  long long dp[n + 1];
  memset(dp, 0, sizeof(dp));
  dp[1] = 1;
  sort(v.begin(), v.end());
  for (long long i = 2; i <= n; i++) {
    for (long long x : v) {
      if (i - x >= 1) {
        dp[i] += dp[i - x];
        if (dp[i] > 998244353) dp[i] %= 998244353;
      } else
        break;
    }
  }
  cout << dp[n] << "\n";
  return 0;
}
