#include <bits/stdc++.h>
using ll = long long;
using namespace std;
int main() {
  const int mod = 998244353;
  int n, k;
  cin >> n >> k;
  vector<int> dp(n, 0), rui(n + 1), l(k), r(k);
  for (int i = 0; i < (k); i++) {
    cin >> l[i] >> r[i];
  }
  dp[0] = 1;
  rui[0] = 0;
  rui[1] = 1;
  for (int i = 1; i < n; i++) {
    for (int j = 0; j < (k); j++) {
      dp[i] += rui[max(i - l[j] + 1, 0)] - rui[max(i - r[j], 0)];
      dp[i] %= mod;
    }
    rui[i + 1] = rui[i] + dp[i];
    rui[i + 1] %= mod;
  }
  cout << (dp[n - 1] + mod) % mod << endl;
}
