#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using vl = vector<ll>;
using vvl = vector<vl>;
ll gcd(ll a, ll b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
const ll MOD = 998244353;
const ll MAX = 2000001;
ll mod(ll a) { return a % MOD; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a, b); }
int main() {
  ll n, k;
  cin >> n >> k;
  vl dp(3 * n, 0LL);
  vl imos(3 * n);
  dp[0] = 1;
  vvl table(k, vl(2));
  for (int i = 0; i < (k); i++) {
    cin >> table[i][0] >> table[i][1];
  }
  ll now = 0;
  for (ll i = 0; i < n; i++) {
    if (i != 0) {
      now += mod(imos[i]);
      dp[i] = mod(now);
    }
    now = mod(now);
    for (int j = 0; j < (k); j++) {
      imos[i + table[j][0]] += dp[i];
      imos[i + table[j][1] + 1] -= dp[i];
    }
  }
  cout << mod(dp[n - 1]) << endl;
}
