#include <bits/stdc++.h>
using namespace std;
const int mod = 998244353;
long long int dp[200200];
long long int bit[200200];
void add(int x, long long int val) {
  for (x; x <= 200000; x += (x & -x)) {
    bit[x] += val;
    bit[x] %= mod;
  }
}
long long int get(int x) {
  long long int res = 0;
  for (x; x > 0; x -= (x & -x)) {
    res += bit[x];
    res %= mod;
  }
  return res;
}
int main() {
  int n, i, j, k, x, y, ans, curr, temp, m;
  int tc;
  cin >> n >> k;
  add(1, 1);
  vector<pair<int, int> > v;
  for (i = 1; i <= k; i++) {
    cin >> x >> y;
    v.push_back({x, y});
  }
  sort(v.begin(), v.end());
  for (i = 2; i <= n; i++) {
    dp[i] = 0;
    for (auto x : v) {
      if (x.first > i - 1) break;
      int r = i - x.first;
      int l = i - min(i - 1, x.second);
      dp[i] += get(r) - get(l - 1);
      while (dp[i] < 0) dp[i] += mod;
    }
    add(i, dp[i]);
  }
  cout << dp[n] << endl;
  return 0;
}
