#include <bits/stdc++.h>
using namespace std;
const int maxN = 4 * 100000;
long dp[maxN + 1];
int N, K;
int main() {
  cin >> N >> K;
  int l, r;
  vector<int> list;
  for (int i = 0; i < K; i++) {
    cin >> l >> r;
    for (int j = l; j <= r; j++) {
      list.__emplace_back(j);
    }
  }
  dp[N] = 1;
  for (int i = N; i > 0; i--) {
    for (int x : list) {
      dp[i] += dp[i + x];
    }
    if (dp[i] > 998244353) {
      dp[i] %= 998244353;
    }
  }
  cout << dp[1];
  return 0;
}
