#include <bits/stdc++.h>
using namespace std;
int dp[1000001];
void solve() {
  int n, k;
  cin >> n >> k;
  vector<pair<int, int>> v(k);
  for (int i = 0; i < k; i++) {
    int a, b;
    cin >> a >> b;
    v[i] = {a, b};
  }
  sort(v.begin(), v.end());
  dp[1] = 1;
  for (int i = 0; i <= n; i++) {
    for (int j = 0; j < k; j++) {
      if (v[j].first > i)
        break;
      else {
        for (int x = v[j].first; x <= v[j].second; x++) {
          if (x > i) break;
          dp[i] = (dp[i] + dp[i - x]) % 998244353;
        }
      }
    }
  }
  cout << dp[n] << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int t = 1;
  while (t--) solve();
  return 0;
}
