#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1000000007;
const ll LNF = 9223372036854775807LL;
int main() {
  int N, K;
  cin >> N >> K;
  vector<pair<int, int> > x(N);
  vector<ll> dp(N + 1, 0);
  ll mmm = 998244353;
  for (int i = 0; i < K; i++) {
    int l, r;
    cin >> l >> r;
    x[i] = make_pair(l, r);
  }
  int cnt = 0;
  dp[0] = 1;
  for (int i = 0; i <= N; i++) {
    for (int j = 0; j < K; j++) {
      for (int k = x[j].first; k <= x[j].second; k++) {
        if (i + k <= N) dp[i + k] += dp[i];
        dp[i + k] = dp[i + k] % mmm;
      }
    }
  }
  cout << dp[N - 1] << endl;
  return 0;
}
