#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int mod = 998244353;
int dp[200010];
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> act;
  for (int i = 0; i < k; i++) {
    int l, r;
    cin >> l >> r;
    for (int i = l; i < r + 1; ++i) {
      act.emplace_back(i);
    }
  }
  dp[0] = 1;
  for (int i = 0; i < n; i++) {
    for (auto a : act) {
      int nx = i + a;
      if (nx >= n) continue;
      dp[nx] = (dp[nx] + dp[i]) % mod;
    }
  }
  int ans = dp[n - 1];
  cout << ans << endl;
  return 0;
}
