#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, k;
  cin >> n >> k;
  vector<int> steps;
  vector<long long int> dp(n);
  dp[0] = 1;
  for (int i = 0; i < k; ++i) {
    int start, end;
    cin >> start >> end;
    for (int j = start; j <= end; ++j) steps.push_back(j);
  }
  for (int i = 1; i < n; ++i) {
    for (int step : steps) {
      if (i - step >= 0) {
        dp[i] = (dp[i] + dp[i - step]) % 998244353;
      }
    }
  }
  cout << dp[n - 1] << '\n';
  return 0;
}
