#include <bits/stdc++.h>
using namespace std;
int main() {
  clock_t tim;
  tim = clock();
  const long long MOD = 998244353;
  {
    int n, k;
    cin >> n >> k;
    vector<int> coins;
    for (int i = 0; i < k; i++) {
      int L, R;
      cin >> L >> R;
      for (int i = L; i <= R; i++) {
        coins.push_back(i);
      }
    }
    sort(coins.begin(), coins.end());
    long long dp[n + 1];
    fill(dp, dp + n + 1, 0);
    dp[1] = 1;
    for (int i = 2; i < n + 1; i++) {
      for (int j = 0; j < coins.size() && i - coins[j] >= 1; j++) {
        dp[i] = (dp[i] + dp[i - coins[j]]) % MOD;
      }
    }
    cout << dp[n] << endl;
  }
  return 0;
}
