#include <bits/stdc++.h>
using namespace std;
const long long MOD = 998244353;
int main() {
  long long n, k;
  cin >> n >> k;
  vector<pair<int, int>> imos(k);
  for (int i = 0; i < k; i++) {
    int L, R;
    cin >> L >> R;
    imos[i] = make_pair(L, R + 1);
  }
  vector<long long> dp(500000, 0);
  dp[1] = 1;
  dp[2] = -1;
  for (int i = 0; i < 500000; i++) {
    if (i > 0) dp[i] += dp[i - 1];
    dp[i] %= MOD;
    for (int j = 0; j < k; j++) {
      int L = imos[j].first;
      int R = imos[j].second;
      dp[i + L] += dp[i];
      dp[i + L] %= MOD;
      dp[i + R] -= dp[i];
      dp[i + R] = (dp[i + R] + MOD) % MOD;
    }
  }
  cout << dp[n] << endl;
}
