#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MOD = 998244353;
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> l(k), r(k), dp(n + 5), sum(n + 5);
  for (int i = 0; i < (int)(k); i++) cin >> l[i] >> r[i];
  dp[1]++;
  sum[1]++;
  for (int i = 2; i <= n; i++) {
    for (int j = 0; j < (int)(k); j++) {
      int a = i - r[j];
      int b = i - l[j];
      a = max(a, 1);
      if (b < 0) continue;
      dp[i] += sum[b] - sum[a - 1];
      dp[i] %= MOD;
    }
    sum[i] = dp[i] + sum[i - 1];
    sum[i] %= MOD;
  }
  cout << (dp[n] + MOD) % MOD << endl;
  return 0;
}
