#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1 << 25;
const int MOD = 998244353;
const int N = 2 * 1e5 + 100;
int l, r;
vector<int> s;
int dp[N];
int main() {
  int n, k;
  cin >> n >> k;
  for (int i = 0; i < (k); i++) {
    cin >> l >> r;
    for (int i = l; i <= r; i++) s.push_back(i);
  }
  int m = s.size();
  dp[0] = 1;
  for (int i = 0; i < (n); i++) {
    for (int j = 0; j < (m); j++) {
      if (i + s[j] >= n) continue;
      dp[i + s[j]] += dp[i];
      dp[i + s[j]] %= MOD;
    }
  }
  cout << dp[n - 1] << endl;
  return 0;
}
