#include <bits/stdc++.h>
using namespace std;
const long long mod = 998244353;
const long long N = 2e5 + 5;
unordered_map<long long, vector<long long>> adj;
vector<long long> vis(300005, 0);
vector<long long> p(100005, 0);
long long c[100005];
long long cnt;
long long n;
void dfs(long long node) {
  if (vis[node]) return;
  vis[node] = 1;
  cnt++;
  for (auto i : adj[node]) {
    dfs(i);
  }
}
struct range {
  long long l;
  long long r;
  long long index;
};
bool cmp(range& p1, range& p2) { return p1.l < p2.l; }
int main() {
  long long n, k;
  cin >> n >> k;
  long long a, b;
  vector<pair<long long, long long>> v;
  long long dp[n + 1];
  while (k--) {
    cin >> a >> b;
    v.push_back(make_pair(a, b));
  }
  memset(dp, 0, sizeof(dp));
  long long pre[n + 1];
  pre[0] = 0;
  pre[1] = 1;
  dp[1] = 1;
  long long j, i;
  for (i = 2; i <= n; i++) {
    for (j = 0; j < v.size(); j++) {
      long long r = max(0LL, i - v[j].first);
      long long l = max(0LL, i - v[j].second - 1);
      dp[i] = (dp[i] + pre[l] - pre[r]) % mod;
    }
    pre[i] = pre[i - 1] + dp[i];
  }
  cout << dp[n];
}
