#include <bits/stdc++.h>
using namespace std;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
using ll = long long int;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using mii = map<int, int>;
using pii = pair<int, int>;
const int inf = 1e9;
const ll infL = (ll)1e18;
const int N = 100005;
const ll mod = (ll)1e9 + 7;
const ll mod2 = 998244353LL;
int n, k;
set<int> s;
ll dp[2 * N];
vi vis;
ll solve(int pos) {
  if (pos == n) return 1LL;
  ll& res = dp[pos];
  if (res != -1) return res;
  ll ans = 0LL;
  for (int c : vis) {
    if (pos + c > n) continue;
    ans += solve(pos + c);
    ans %= mod2;
  }
  return res = ans;
}
int32_t main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  cin >> n >> k;
  vi used(N, 0);
  for (int i = 0; i < k; i++) {
    int u, v;
    cin >> u >> v;
    for (int x = u; x <= v; x++) {
      if (!used[x]) {
        vis.push_back(x);
        used[x] = 1;
      }
    }
  }
  memset(dp, -1, sizeof dp);
  sort(vis.begin(), vis.end());
  ll ans = solve(1);
  cout << ans << '\n';
  return 0;
}
