#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int mod = 998244353;
const int N = 200010;
unsigned long long p_hash(unsigned long long x, unsigned long long y) {
  return (x + y) * (x + y + 1) / 2 + y;
}
long long gcd(long long x, long long y) { return y ? gcd(y, x % y) : x; }
vector<int> l(11), r(11);
int cnt[N];
int sum[N];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, k;
  cin >> n >> k;
  for (int i = 1; i <= k; i++) cin >> l[i] >> r[i];
  cnt[1] = 1;
  sum[1] = 1;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= k; j++) {
      int a = l[j], b = r[j];
      if (i - a < 1) continue;
      cnt[i] = (cnt[i] + sum[i - a] - sum[max(i - b, 1) - 1]) % mod;
    }
    sum[i] = (sum[i - 1] + cnt[i]) % mod;
  }
  cout << (cnt[n] + mod) % mod << endl;
  return 0;
}
