#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MOD = 998244353;
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> l(k), r(k);
  for (int i = 0; i < k; i++) cin >> l[i] >> r[i];
  vector<ll> dp(n + 1), dpsum(n + 1);
  dp[1] = 1;
  for (int i = 2; i <= n; i++) {
    for (int j = 0; j < k; j++) {
      for (int k = l[j]; k <= r[j]; k++) {
        if (i - k < 0) continue;
        dp[i] += dp[i - k];
        dp[i] %= MOD;
      }
    }
  }
  cout << (dp[n]) << "\n";
  return 0;
}
