#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  vector<pair<int, int>> A;
  for (int i = 0; i < k; ++i) {
    int l, r;
    cin >> l >> r;
    A.push_back({l, r});
  }
  sort(A.begin(), A.end());
  vector<int> jump;
  for (int i = 0; i < A.size(); ++i) {
    for (int j = A[i].first; j <= A[i].second; ++j) {
      jump.push_back(j);
    }
  }
  vector<long long> Dp(n, 0);
  Dp[0] = 1;
  for (int i = 0; i < n; ++i) {
    for (int x : jump) {
      if (i + x < n)
        Dp[i + x] = (Dp[i + x] + Dp[i]) % 998244353;
      else
        break;
    }
  }
  cout << Dp[n - 1] << "\n";
}
