#include <bits/stdc++.h>
using namespace std;
int mod = 998244353;
int main() {
  int n, k;
  cin >> n >> k;
  vector<pair<int, int>> p(k);
  for (int i = 0; i < k; i++) {
    cin >> p[i].first >> p[i].second;
  }
  vector<int> v;
  for (int i = 0; i < k; i++) {
    for (int j = p[i].first; j <= p[i].second; j++) {
      v.push_back(j);
    }
  }
  sort(v.begin(), v.end());
  vector<int> dp(n + 1, 0);
  dp[1] = 1;
  for (int i = 2; i <= n; i++) {
    for (int j = 0; j < v.size(); j++) {
      if (i - v[j] >= 1)
        dp[i] = (dp[i] + dp[i - v[j]]) % mod;
      else
        break;
    }
  }
  cout << dp[n] << endl;
  return 0;
}
