#include <bits/stdc++.h>
#define rep(i,a,n) for (int i=a; i<n; i++)
#define ll long long
#define MOD 998244353
using namespace std;;
 
int main() {
  int N, K; cin >> N >> K;
  vector<int> L(K),R(K); rep(i,0,K) cin >> L[i] >> R[i];
  vector<ll> dp(N + 1, 0); dp[0] = 1; dp[1] = -1;
  rep(i,0,N) { 
    dp[i] = ((dp[i] % MOD) + MOD) % MOD;
    dp[i + 1] = (dp[i + 1] + dp[i]) % MOD;
    rep(j,0,K) {
      if (i + L[j] < N) dp[i + L[j]] += dp[i];
      if (i + R[j] + 1 < N) dp[i + R[j] + 1] -= dp[i];
    }
  }
  cout << dp[N - 1] << endl;
}