#include <bits/stdc++.h>
using namespace std;
const long long mod = 998244353;
const int N = 200006;
const long long INF = 1e18;
long long f[N];
long long dp[N];
void upd(int pos, long long val) {
  for (; pos < N; pos += pos & (-pos)) {
    f[pos] += val;
    f[pos] %= mod;
  }
}
long long q(int pos) {
  long long ans = 0;
  for (; pos; pos -= pos & (-pos)) {
    ans += f[pos];
    ans %= mod;
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  vector<pair<int, int>> in;
  for (int i = 1; i <= k; i++) {
    int x, y;
    cin >> x >> y;
    in.push_back({x, y});
  }
  dp[1] = 1;
  for (int i = 1; i <= n; i++) {
    if (i > 1) dp[i] = q(i);
    for (int j = 0; j < k; j++) {
      int l = i + in[j].first;
      int r = i + in[j].second;
      r = min(r, n);
      if (l <= n) {
        upd(l, +dp[i]);
        upd(r + 1, -dp[i]);
      }
    }
  }
  cout << dp[n] << '\n';
  return 0;
}
