#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k, sz, l, r, ans = 0;
  cin >> n >> k;
  vector<int> coins, dp(n + 5, 0);
  while (k--) {
    cin >> l >> r;
    for (int i = l; i <= r; i++) coins.push_back(i);
  }
  dp[0] = 1;
  for (int i = 0; i <= n; i++) {
    for (auto lol : coins) {
      if (i + lol <= n + 1) {
        dp[i + lol] = (dp[i + lol] + dp[i]) % 998244353;
      }
    }
  }
  cout << dp[n - 1] << endl;
  return 0;
}
