#include <bits/stdc++.h>
using namespace std;
int main() {
  int mod = 998244353;
  int n, k, a, b, l, r;
  cin >> n >> k;
  vector<int> sum(n + 1, 0);
  vector<int> ans(n + 1, 0);
  vector<pair<int, int>> pair;
  for (int i = 0; i < (int)(k); i++) {
    cin >> a >> b;
    pair.push_back(make_pair(a, b));
  }
  sum[0] = 0;
  sum[1] = 1;
  ans[1] = 1;
  for (int i = 2; i <= n; i++) {
    for (int j = 0; j < (int)(k); j++) {
      l = i - pair.at(j).second;
      r = i - pair.at(j).first;
      if (r < 0) continue;
      l = max(l, 1);
      ans[i] += sum[r] - sum[l - 1];
      ans[i] %= mod;
    }
    sum[i] = (ans[i] + sum[i - 1]) % mod;
  }
  if (ans[n] < 0) ans[n] += mod;
  cout << ans[n] << endl;
}
