#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
const int inf = 1e9;
const long long INF = 1LL << 60;
long long dp[15][200050];
int main() {
  int n, k;
  cin >> n >> k;
  vector<long long> l(k), r(k);
  for (int i = 0; i < (int)(n); i++) cin >> l[i] >> r[i];
  long long MOD = 998244353;
  vector<long long> dp(n + 1);
  vector<long long> sum(n + 1);
  dp[1] = 1;
  sum[1] = 1;
  for (int i = 2; i <= n; i++) {
    for (int j = 0; j < (int)(k); j++) {
      int li = i - r[j];
      int ri = i - l[j];
      if (ri < 0) continue;
      li = max(li, 1);
      dp[i] += sum[ri] - sum[li - 1];
      dp[i] %= MOD;
    }
    sum[i] = sum[i - 1] + dp[i];
    sum[i] %= MOD;
  }
  cout << dp[n] << endl;
}
