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