#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 998244353;
int main() {
  ll n, k;
  cin >> n >> k;
  vector<ll> nums;
  for (int i = 0; i < k; ++i) {
    int l, r;
    cin >> l >> r;
    for (int i = l; i <= r; ++i) {
      nums.emplace_back(i);
    }
  }
  vector<int> dp(n + 1, 0);
  dp[1] = 1;
  for (int i = 2; i <= n; ++i) {
    for (auto num : nums) {
      if (i >= num) {
        dp[i] += (dp[i - num] % MOD);
        dp[i] = (dp[i] % MOD);
      }
    }
  }
  cout << dp[n] << endl;
  return 0;
}
