#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MOD = 998244353;
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> s;
  for (int i = 0; i < k; i++) {
    int l, r;
    cin >> l >> r;
    for (int j = l; j <= r; j++) {
      s.push_back(j);
    }
  }
  int N = s.size();
  sort(s.begin(), s.end());
  vector<ll> dp(n, 0);
  dp[0] = 1;
  for (int i = 1; i < n; i++) {
    for (auto x : s) {
      if (i - x < 0) break;
      dp[i] = (dp[i] + dp[i - x]) % MOD;
    }
  }
  cout << dp[n - 1] << endl;
  return 0;
}
