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