#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main(void) {
  int N, K;
  cin >> N >> K;
  vector<pair<int, int>> segs;
  int l, r;
  for (int i = 0; (i) < (K); (i)++) {
    cin >> l >> r;
    segs.push_back({l, r});
  }
  sort(segs.begin(), segs.end());
  vector<int> dp(N + 1, 0);
  dp[0] = 1;
  for (int now = 0; (now) < (N); (now)++) {
    for (auto seg : segs) {
      if (now + seg.first >= N) {
        break;
      }
      for (int i = seg.first; i <= seg.second; ++i) {
        if (now + i < N) {
          dp[now + i] += dp[now];
          dp[now + i] %= 998244353;
        }
      }
    }
  }
  cout << dp[N - 1] % 998244353 << endl;
  return 0;
}
