#include <bits/stdc++.h>
using namespace std;
using ll = long long;
void setIO(string name = "") {
  ios_base::sync_with_stdio(NULL);
  cin.tie(NULL);
  cout.tie(NULL);
  if ((int)(name).size()) {
    freopen((name + ".in").c_str(), "r", stdin);
    freopen((name + ".out").c_str(), "w", stdout);
  }
}
const int inf = 1e9;
const ll INF = 1e18;
const int mod = 998244353;
const int MAXN = 2e5 + 5;
int n, k;
int l[MAXN], r[MAXN];
set<int> v;
ll dp[MAXN];
void solve() {
  cin >> n >> k;
  for (int i = 1; i <= k; i++) {
    cin >> l[i] >> r[i];
    for (int j = l[i]; j <= r[i]; j++) {
      v.insert(j);
    }
  }
  dp[1] = 1;
  for (int i = 1; i < n; i++) {
    for (int j : v) {
      if (i + j > n) continue;
      dp[i + j] += dp[i];
      dp[i + j] %= mod;
    }
  }
  cout << dp[n];
}
int main() {
  setIO();
  int tt = 1;
  while (tt--) {
    solve();
  }
  return 0;
}
