#include <bits/stdc++.h>
using namespace std;
int n;
int num_of_segments;
vector<int> step_sizes;
bool calculated[200100];
unsigned long long int ways_of_getting_to[200100];
unsigned long long int dp(int index) {
  if (!calculated[index]) {
    for (int step_size : step_sizes) {
      int previous_cell = index - step_size;
      if (previous_cell >= 1) {
        ways_of_getting_to[index] += dp(previous_cell);
      } else {
        break;
      }
    }
    calculated[index] = true;
  }
  return ways_of_getting_to[index];
}
int main() {
  scanf("%d %d", &n, &num_of_segments);
  for (int i = 0; i < num_of_segments; i++) {
    int l, r;
    scanf("%d %d", &l, &r);
    for (int i = l; i <= r; i++) {
      step_sizes.push_back(i);
    }
  }
  sort(step_sizes.begin(), step_sizes.end());
  ways_of_getting_to[1] = 1;
  calculated[1] = true;
  auto result = dp(n);
  printf("%d\n", dp(n) % 998244353);
}
