#include <bits/stdc++.h>
using namespace std;
const int mod = 998244353;
int n, k;
bool flag[200010];
long long dp[200010];
int main() {
  cin >> n >> k;
  int x, y;
  for (int i = 1; i <= k; i++) {
    cin >> x >> y;
    for (int j = x; j <= y; j++) flag[j] = true;
  }
  dp[1] = 1;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; i + j <= n; j++) {
      if (flag[j]) {
        dp[i + j] += dp[i];
        dp[i + j] %= mod;
      }
    }
  }
  cout << dp[n];
  cout << endl;
  return 0;
}
