#include <bits/stdc++.h>
using namespace std;
const int N = 200000 + 5, M = 50000 + 5, INF = 0x3f3f3f3f;
const int MOD = 998244353;
pair<int, int> a[15];
int s[N], cnt;
int dp[N];
int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= k; ++i) {
    cin >> a[i].first >> a[i].second;
    for (int j = a[i].first; j <= a[i].second; ++j) {
      s[++cnt] = j;
    }
  }
  dp[1] = 1;
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= cnt && s[j] < i; ++j) {
      dp[i] = (dp[i] + dp[i - s[j]]) % MOD;
    }
  }
  printf("%d\n", dp[n]);
  return 0;
}
