#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
constexpr int mod = 998244353;
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> dp(n + 2, 0);
  vector<int> l(k), r(k);
  rep(i,k) cin >> l[i] >> r[i];
  dp[0] = 0;
  dp[1] = 1;
  for (int i = 2; i <= n; i++) {
    for (int j = 0; j < k; j++) {
      (dp[i] += (dp[max(0, i - l[j])] - dp[max(0, i - r[j] - 1)] + mod) % mod) %= mod;
    }
    (dp[i + 1] += dp[i]) %= mod;
  }

  cout << dp[n] << endl;
  return 0; 
}