#include <bits/stdc++.h>
using namespace std;
long long dx[] = {1, -1, 0, 0, 1, 1, -1, -1};
long long dy[] = {0, 0, 1, -1, 1, -1, 1, -1};
const long long MAX = 2e5, mod = 998244353;
long long n, k, a, b, dp[MAX], sum[MAX];
vector<pair<long long, long long> > v;
long long getSum(long long a, long long b) {
  if (b < 0) return 0;
  a = max(a, 0LL);
  if (a == 0) return sum[b];
  return (sum[b] - sum[a - 1]) % mod;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  ;
  cin >> n >> k;
  for (long long i = 0; i < k; i++) {
    cin >> a >> b;
    v.push_back(make_pair(a, b));
  }
  dp[0] = sum[0] = 1;
  for (long long i = 1; i < n; i++) {
    for (long long j = 0; j < k; j++) {
      dp[i] += getSum(i - v[j].second, i - v[j].first);
      dp[i] %= mod;
    }
    sum[i] = (sum[i - 1] + dp[i]) % mod;
  }
  cout << dp[n - 1];
}
