#include <bits/stdc++.h>
using namespace std;
vector<long long> dp;
const int mod = 998244353;
int main() {
  int n, k;
  cin >> n >> k;
  dp.resize(n + 1);
  dp[1] = 1;
  vector<int> a;
  for (int i = 0; i < k; i++) {
    int l, r;
    cin >> l >> r;
    for (int j = l; j <= r; j++) {
      a.push_back(j);
    }
  }
  sort(a.begin(), a.end());
  for (int i = 1; i < n; i++) {
    for (int j = 0; j < a.size(); j++) {
      if (i + a[j] > n) break;
      dp[i + a[j]] += dp[i];
      dp[i + a[j]] %= mod;
    }
  }
  cout << dp[n] << endl;
}
