#include <bits/stdc++.h>
using namespace std;
const int mod = 998244353;
int main() {
  int n, k;
  cin >> n >> k;
  set<int> moves;
  for (int i = 0; i < k; i++) {
    int x, y;
    cin >> x >> y;
    for (int j = x; j <= y; j++) {
      moves.insert(j);
    }
  }
  vector<int> dp(n + 1, 0);
  dp[1] = 1;
  for (int i = 2; i <= n; i++) {
    for (int move : moves) {
      if (i - move >= 1) dp[i] += dp[i - move];
      dp[i] %= mod;
    }
  }
  cout << dp[n];
  return 0;
}
