#include <bits/stdc++.h>
using namespace std;
const long long MAX5 = 1e+5 + 7;
const long long MAX7 = 1e+7 + 7;
const long long MAXN = MAX7;
const long long INF = 0x7f7f7f7f7f7f7f7f;
const int INFi = 0x7f7f7f7f;
const long long MOD = 998244353;
const long long N = 2 * 1e6;
long long T = 1;
long long n, x, y, m;
string second, t;
vector<long long> a;
long long dp[N];
long long vis[N];
void MAIN() {
  dp[1] = 1;
  vis[1] = 1;
  cin >> n >> m;
  for (long long i = 0; i < m; i++) {
    cin >> x >> y;
    for (long long j = x; j <= y; j++) a.push_back(j);
  }
  for (long long i = 1; i < n; i++) {
    if (vis[i] == 0) continue;
    for (auto it : a) {
      if (i + it > n) continue;
      dp[i + it] += dp[i];
      dp[i + it] %= MOD;
      vis[i + it] = 1;
    }
  }
  cout << dp[n];
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cout << fixed;
  cout << setprecision(12);
  ;
  mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
  ;
  while (T--) {
    MAIN();
  }
  return 0;
}
