#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MOD = 998244353;
const ll INF = 1e16;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, k;
  cin >> n >> k;
  int b[k][2];
  for (int i = 0; i < k; i++) {
    cin >> b[i][0] >> b[i][1];
  }
  vector<int> dp(n + 1, 0);
  dp[1] = 1;
  for (int i = 2; i <= n; i++) {
    for (int j = 0; j < k; j++) {
      dp[i] += dp[max(i - b[j][0], 0)] - dp[max(i - b[j][1] - 1, 0)];
      dp[i] %= MOD;
    }
    dp[i] += dp[i - 1];
    dp[i] %= MOD;
  }
  int ways = dp[n] - dp[n - 1];
  cout << ((ways < 0) ? ways + MOD : ways % MOD) << "\n";
  return 0;
}
