#include <bits/stdc++.h>
using namespace std;
const long long N = 2e6 + 5;
const long long mod = 998244353;
long long ans[N];
long long s[N];
long long n;
long long k;
signed main() {
  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++) s[j] = 1;
  }
  ans[1] = 1;
  for (long long i = 1; i <= n; i++)
    for (long long j = 1; j <= i; j++)
      ans[i] += s[j] * ans[i - j], ans[i] %= mod;
  cout << ans[n] << endl;
}
