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