#include <bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;
const int INF = 0x3f3f3f3f;
const int MOD = 998244353;
void add(int& A, int B) {
  A += B;
  if (A >= MOD) A -= MOD;
}
void miu(int& A, int B) {
  A -= B;
  if (A < 0) A += MOD;
}
pair<int, int> seg[11];
int n, k, dp[200000 + 20];
int main() {
  ios::sync_with_stdio(false);
  cin >> n >> k;
  for (int i = 1; i <= k; ++i) cin >> seg[i].first >> seg[i].second;
  dp[0] = 1;
  for (int i = 1; i <= k; ++i) {
    int sum = 0;
    for (int j = 1; j <= n; ++j) {
      if (j - seg[i].first >= 0) add(sum, dp[j - seg[i].first]);
      if (j - seg[i].second - 1 >= 0) miu(sum, dp[j - seg[i].second - 1]);
      add(dp[j], sum);
    }
  }
  cout << dp[n] << endl;
  return 0;
}
