#include <bits/stdc++.h>
using namespace std;
const int mod = 998244353;
int n, m;
int l, r;
int a[1000001];
bool vis[1000001];
int dp[1000001];
int main() {
  int num = 0;
  scanf("%d %d", &n, &m);
  for (int i = 0; i < m; i++) {
    scanf("%d %d", &l, &r);
    for (int j = l; j <= r; j++) {
      if (vis[j]) continue;
      vis[j] = true;
      a[num++] = j;
    }
  }
  sort(a, a + num);
  dp[0] = 1;
  for (int i = 0; i <= n - 1; i++) {
    for (int j = 0; j < num; j++) {
      if (i + a[j] > n - 1) break;
      dp[i + a[j]] = (dp[i] + dp[i + a[j]]) % mod;
    }
  }
  printf("%d\n", dp[n - 1]);
  return 0;
}
