#include <bits/stdc++.h>
using namespace std;
const long long N = 200001;
long long dp[N];
void solve() {
  long long n, q;
  cin >> n >> q;
  vector<pair<long long, long long>> v;
  for (long long i = 0; i < q; i++) {
    long long x, y;
    cin >> x >> y;
    v.push_back({x, y});
  }
  vector<long long> add;
  dp[1] = 1;
  for (long long i = 1; i <= n; i++) {
    for (long long j = 0; j < q; j++) {
      if (i >= v[j].first && i <= v[j].second) {
        add.push_back(i);
        break;
      }
    }
  }
  for (long long i = 1; i <= n; i++) {
    for (long long j = 0; j < add.size(); j++) {
      if (i - add[j] >= 1)
        dp[i] =
            ((dp[i] % 998244353) + (dp[i - add[j]] % 998244353)) % 998244353;
    }
  }
  cout << dp[n] << "\n";
}
int32_t main() {
  ios::sync_with_stdio(0), cin.tie(NULL), cout.tie(NULL);
  long long T = 1;
  while (T--) {
    solve();
  }
  return 0;
}
