#include <bits/stdc++.h>
using namespace std;
int mod = 998244353;
void solve() {
  int n, k;
  cin >> n >> k;
  vector<int> v;
  vector<int> dp(n + 1, 0);
  for (int i = 0; i < k; i++) {
    int x, y;
    cin >> x >> y;
    for (int j = x; j <= y; j++) v.push_back(j);
  }
  sort(v.begin(), v.end());
  dp[1] = 1;
  for (int i = 2; i < n + 1; i++) {
    for (int j = 0; j < v.size(); j++) {
      int step = v[j];
      if (step > i - 1) break;
      dp[i] = (dp[i] + dp[i - step]) % mod;
    }
  }
  cout << dp[n] << endl;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long T = 1;
  while (T--) {
    solve();
  }
  return 0;
}
