#include <bits/stdc++.h>
using namespace std;
int n, k, cnt;
int step[200005];
long long ans;
long long dp[200005], dp1[200005];
int main() {
  cin >> n >> k;
  for (int i = 1; i <= k; i++) {
    int l, r;
    cin >> l >> r;
    for (int j = l; j <= r; j++) step[++cnt] = j;
  }
  sort(step + 1, step + 1 + cnt);
  dp[1] = 1ll;
  dp1[1] = 1ll;
  int num = 10000000 / cnt;
  if (num < cnt) {
    for (int i = 1; i <= num; i++)
      for (int j = 1; j <= cnt; j++)
        if (i - step[j] > 0)
          (dp1[i] += dp1[i - step[j]]) %= 998244353;
        else
          break;
    for (int i = 1; i <= n; i++)
      for (int j = 1; j <= num; j++)
        if (i - dp1[j] > 0) (dp[i] += dp[i - j] * dp1[j]) %= 998244353;
  } else {
    for (int i = 1; i <= n; i++)
      for (int j = 1; j <= cnt; j++)
        if (i - step[j] > 0)
          (dp[i] += dp[i - step[j]]) %= 998244353;
        else
          break;
  }
  cout << dp[n] % 998244353 << endl;
}
