#include <bits/stdc++.h>
using ll = long long;
const int inf = 99999999;
const ll mod = 998244353;
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  map<int, int> mp;
  for (int i = 0; i < k; i++) {
    int l, r;
    cin >> l >> r;
    for (int i = l; i <= r; i++) {
      mp[i] = 1;
    }
  }
  vector<ll> dp(n + 1000, 0);
  dp[1] = 1;
  for (int i = 1; i <= n; i++) {
    for (auto p : mp) {
      if (i + p.first > n) break;
      dp[i + p.first] += dp[i];
      dp[i + p.first] %= mod;
    }
  }
  dp[n] %= mod;
  cout << dp[n] << endl;
  return 0;
}
