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