#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
const int p = 998244353;
int a[N], b[N];
long long dp[N];
int main() {
  int n, k;
  cin >> n >> k;
  for (int i = 1; i <= k; i++) cin >> a[i] >> b[i];
  dp[1] = 1;
  for (int ii = 2; ii <= n; ii++)
    for (int i = 1; i <= k; i++) {
      for (int j = a[i]; j <= b[i]; j++)
        if (ii > j) dp[ii] = (dp[ii] + dp[ii - j]) % p;
    }
  cout << dp[n] << endl;
  return 0;
}
