#include <bits/stdc++.h>
using namespace std;
struct _IO {
  _IO() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
  }
} _io;
long long exgcd(long long a, long long b, long long& x, long long& y) {
  if (!b) {
    x = 1;
    y = 0;
    return a;
  }
  long long d = exgcd(b, a % b, x, y);
  long long t = x;
  x = y;
  y = t - (a / b) * y;
  return d;
}
long long getInv(long long a, long long mod) {
  long long x, y;
  return exgcd(a, mod, x, y) == 1 ? (x % mod + mod) % mod : -1;
}
const long long maxn = 2e5 + 5, mod = 998244353;
long long dp[maxn], sum[maxn];
bool used[maxn];
int main() {
  long long n, k;
  vector<long long> s;
  vector<pair<long long, long long>> seg;
  cin >> n >> k;
  while (k--) {
    long long a, b;
    cin >> a >> b;
    seg.push_back({a, b});
  }
  sort(seg.begin(), seg.end());
  dp[1] = 1;
  sum[1] = 1;
  for (long long i = 1; i <= n; ++i) {
    for (pair<long long, long long>& j : seg) {
      if (i - j.second - 1 >= 0)
        dp[i] = (dp[i] + sum[i - j.first] - sum[i - j.second - 1]) % mod;
      else
        dp[i] = (dp[i] + sum[i - j.first] - sum[0]) % mod;
    }
    sum[i] = sum[i - 1] + dp[i];
  }
  cout << dp[n] % mod << '\n';
  return 0;
}
