#include <bits/stdc++.h>
using namespace std;
using pint = pair<int, int>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const double pi = acos(-1);
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ll mod = 998244353;
  ll n, k;
  cin >> n >> k;
  vll l(k);
  vll r(k);
  for (int i = 0; i < (int)(k); i++) {
    cin >> l[i] >> r[i];
  }
  vll dp(1000000, 0);
  dp[0] = 1;
  dp[1] = -1;
  for (int i = 0; i < (int)(n); i++) {
    if (i > 0) dp[i] += dp[i - 1];
    dp[i] %= mod;
    for (int j = 0; j < (int)(k); j++) {
      if (i + l[j] < n) {
        dp[i + l[j]] += dp[i];
        dp[i + l[j]] %= mod;
      }
      if (i + r[j] < n) {
        dp[i + r[j]] -= dp[i];
        dp[i + r[j]] %= mod;
      }
    }
  }
  cout << dp[n - 1] << endl;
}
