#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;

const int MOD = 998244353;
const int N = 200000, K = 10;

int n, k, l[K], r[K];
int dp[2 * N];

int main() {
  cin >> n >> k;
  rep(i, k) cin >> l[i] >> r[i];
  for (int i = 1; i <= n; i++) dp[i] = 0;
  dp[1] = 1;
  dp[2] = -1;
  for (int i = 1; i < n; i++) {
    rep(j, k) {
      dp[i + l[j]] = (dp[i + l[j]] + dp[i]) % MOD;
      dp[i + r[j] + 1] = (dp[i + r[j] + 1] - dp[i]) % MOD;
    }
    dp[i + 1] = (dp[i + 1] + dp[i]) % MOD;
  }
  if (dp[n] < 0) dp[n] += MOD;
  cout << dp[n] << endl;
  return 0;
}