#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 50;
const int inf = 0x3f3f3f3f;
const int MOD = 998244353;
const int HASH = 131;
long long l[maxn], r[maxn];
long long sum[maxn], ans[maxn];
int main() {
  long long n, k;
  cin >> n >> k;
  for (long long i = 1; i <= k; i++) {
    cin >> l[i] >> r[i];
  }
  sum[1] = 1;
  ans[1] = 1;
  for (long long i = 2; i <= n; i++) {
    for (long long j = 1; j <= k; j++) {
      ans[i] = (ans[i] + sum[max((long long)0, i - l[j])] -
                sum[max((long long)0, i - r[j] - 1)]) %
               MOD;
    }
    sum[i] = (sum[i - 1] + ans[i]) % MOD;
  }
  cout << (sum[n] + MOD) % MOD << endl;
  return 0;
}
