#include <bits/stdc++.h>
using namespace std;
const long long maxn = 2e5 + 5;
const long long inf = 0x3f3f3f3f;
const long long mod = 998244353;
long long a[maxn], b[maxn], num = 0;
long long dp[maxn];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n, k;
  cin >> n >> k;
  for (long long i = 1; i <= k; i++) {
    long long l, r;
    cin >> l >> r;
    for (long long j = l; j <= r; j++) {
      if (b[j] == 0) {
        a[++num] = j;
        b[j] = 1;
      }
    }
  }
  sort(a + 1, a + num + 1);
  n--;
  dp[0] = 1;
  for (long long i = 1; i <= n; i++) {
    for (long long j = 1; j <= num; j++) {
      long long x = i - a[j];
      if (x < 0) break;
      dp[i] += dp[x];
      dp[i] %= mod;
    }
  }
  dp[n] %= mod;
  cout << dp[n] << endl;
  return 0;
}
