#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int a, b;
  cin >> a >> b;
  vector<ll> dp(200010, 0);
  dp[1] = 1;
  ll c = 998244353;
  vector<pair<int, int>> pairs(b);
  for (int i = 0; i < b; i++) {
    cin >> pairs[i].first >> pairs[i].second;
  }
  sort(pairs.begin(), pairs.end());
  for (int i = 0; i <= a; i++) {
    for (int j = 0; j < b; j++) {
      for (int k = pairs[j].first; k <= pairs[j].second; k++) {
        if (k >= i) {
          break;
        }
        dp[i] += dp[i - k];
        dp[i] %= c;
      }
    }
  }
  cout << dp[a] << endl;
}
