#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using graph = vector<vector<ll>>;
const long long inf = 2147483647;
const ll INF = 9223372036854775807;
signed main() {
  long long mod = 998244353;
  long long n, k;
  cin >> n >> k;
  set<long long> s;
  for (ll i = 0; i < k; i++) {
    long long a, b;
    cin >> a >> b;
    for (ll j = a; j < b + 1; j++) {
      s.insert(j);
    }
  }
  vector<long long> d(n + 1000, 0);
  d[0] = 1;
  for (ll i = 1; i < n; i++) {
    for (auto j : s) {
      if (i - j < 0) break;
      d[i] += d[i - j];
      d[i] %= mod;
    }
  }
  cout << d[n - 1] << "\n";
  return 0;
}
