#include <bits/stdc++.h>
using namespace std;
const int MOD = 998244353;
const int N = 2E5 + 100;
int n, k;
int s[N];
int cnt;
int dp[N];
int main() {
  scanf("%d%d", &n, &k);
  int l, r;
  for (int i = 1; i <= k; i++) {
    scanf("%d%d", &l, &r);
    for (int j = l; j <= r; j++) {
      s[++cnt] = j;
    }
  }
  sort(s + 1, s + 1 + cnt);
  dp[1] = 1;
  for (int i = 2; i <= n; i++) {
    int k = upper_bound(s + 1, s + cnt + 1, i) - s;
    k--;
    for (int j = 1; j <= k; j++) {
      dp[i] = (dp[i] + dp[i - s[j]]) % MOD;
    }
  }
  cout << dp[n] % MOD << endl;
  return 0;
}
