#include <bits/stdc++.h>
using namespace std;
const int MAX = 10000007;
const long long MOD = 998244353;
template <typename T>
struct FenwickTree {
  int size;
  vector<T> v;
  FenwickTree(int n) {
    size = n;
    v.assign(size + 1, 0);
  }
  FenwickTree(vector<T> arr) {
    size = arr.size();
    v.assign(size + 1, 0);
    for (int i = 0; i < size; i++) {
      upd(i + 1, arr[i]);
    }
  }
  T operator[](int i) {
    T ans = 0;
    for (; i; i -= (i & (-i))) ans = ((long long)ans + v[i]) % MOD;
    return ans;
  }
  void upd(int i, T x) {
    for (; i <= size; i += (i & (-i))) {
      v[i] = (v[i] + x) % MOD;
    }
  }
};
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  vector<vector<int> > v(k, vector<int>(2, 0));
  for (int i = 0; i < (int)k; i++) cin >> v[i][0] >> v[i][1];
  sort(v.begin(), v.end(),
       [](vector<int>& a, vector<int>& b) { return a[0] < b[0]; });
  FenwickTree<long long> ft(n + 1);
  vector<int> dp(n + 1, 0);
  dp[1] = 1;
  for (int i = 1; i < n; i++) {
    dp[i] = ((long long)dp[i] + ft[i]) % MOD;
    for (int j = 0; j < (int)k; j++) {
      int now = dp[i];
      ft.upd(i + v[j][0], now);
      ft.upd(i + v[j][1] + 1, -now);
    }
  }
  cout << (dp[n] + ft[n]) % MOD << '\n';
  return 0;
}
