#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 1e5 + 1;
const int MOD = 998244353;
const int INF = 1e9;
const long long LINF = 1e18;
void solve() {
  int n, k;
  cin >> n >> k;
  vector<int> dp(n + 1), a;
  for (int i = 0; i < k; i++) {
    int l, r;
    cin >> l >> r;
    for (int j = l; j <= r; j++) a.push_back(j);
  }
  sort(a.begin(), a.end());
  dp[1] = 1;
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < a.size() && i + a[j] <= n; j++) {
      dp[i + a[j]] = (dp[i + a[j]] + dp[i]) % MOD;
    }
  }
  cout << dp[n] << "\n";
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int tc;
  tc = 1;
  for (int t = 1; t <= tc; t++) {
    solve();
  }
}
