#include <bits/stdc++.h>
using namespace std;
int n, k;
void solve() {
  cin >> n >> k;
  int k1 = k;
  vector<pair<int, int>> jumps;
  while (k1--) {
    int x, y;
    cin >> x >> y;
    jumps.push_back({x, y});
  }
  sort(jumps.begin(), jumps.end());
  long int dp[n + 1];
  memset(dp, 0, sizeof(dp));
  dp[1] = 1;
  for (int i = 2; i <= n; i++) {
    bool flag = true;
    for (int j = 0; j < k; j++) {
      for (int m = jumps[j].first; m <= jumps[j].second; m++) {
        if (m >= i) {
          flag = false;
          break;
        } else {
          dp[i] = (dp[i] + dp[i - m]) % 998244353;
        }
      }
      if (!flag) break;
    }
  }
  cout << dp[n];
}
int main() {
  {
    ios_base ::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
  };
  int t = 1;
  while (t--) {
    solve();
    cout << "\n";
  }
  return 0;
}
