#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1LL << 60;
ll MOD = 998244353;
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> l(k);
  vector<int> r(k);
  for (int i = 0; i < k; i++) {
    cin >> l[i] >> r[i];
  }
  vector<ll> dp(n + 5, 0);
  dp[1] = 1;
  for (int i = 1; i < n + 5; i++) {
    for (int j = 0; j < k; j++) {
      for (int s = l[j]; s <= min(r[j], n - i); s++) {
        dp[i + s] = (dp[i + s] + dp[i]) % MOD;
      }
    }
  }
  cout << dp[n] << endl;
  return 0;
}
