#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
int INF = 1e9;
ll LINF = 1e18;
int main() {
  int mod = 998244353;
  int n, k;
  cin >> n >> k;
  vector<int> width;
  for (int i = 0; i < (k); ++i) {
    int l, r;
    cin >> l >> r;
    for (int j = l; j <= r; j++) width.push_back(j);
  }
  sort(width.begin(), width.end());
  vector<int> dp(200050, 0);
  dp[1] = 1;
  for (int i = 1; i <= n; i++) {
    for (int v : width) {
      if (v + i > n) break;
      dp[i + v] += dp[i];
      dp[i + v] %= mod;
    }
  }
  cout << dp[n] << endl;
}
