#include <bits/stdc++.h>
using namespace std;
const int mod = 998244353;
int n, k;
pair<int, int> seg[11];
long long dp[100005], f[100005];
void solve() {
  cin >> n >> k;
  for (int i = 1; i <= k; ++i) cin >> seg[i].first >> seg[i].second;
  dp[1] = 1;
  f[1] = 1;
  for (int i = 2; i <= n; ++i) {
    for (int j = 1; j <= k; ++j) {
      int s = max(0, i - seg[j].first);
      int e = max(1, i - seg[j].second);
      dp[i] = (dp[i] + (f[s] - f[e - 1] + mod) % mod) % mod;
    }
    f[i] = (f[i - 1] + dp[i]) % mod;
  }
  cout << dp[n];
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  if (0) {
    int t;
    cin >> t;
    while (t--) solve();
  } else {
    solve();
  }
}
