#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using ii = pair<int, int>;
using ll = long long;
int mod = 998244353;
ll dp[200004];
int b[11];
int e[11];
int main() {
  memset(dp, 0, sizeof dp);
  int n, k;
  cin >> n >> k;
  for (int i = 0; i < k; i++) {
    cin >> b[i] >> e[i];
  }
  ll mod = 998244353;
  dp[0] = 1;
  ll temp[10] = {0};
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < k; j++) {
      int m = e[j];
      int l = b[j];
      int s = i - m - 1;
      int e = i - l;
      if (s >= 0) {
        temp[j] = (temp[j] - dp[s]) % mod;
      }
      if (e >= 0) temp[j] = (temp[j] + dp[e]) % mod;
      dp[i] = (temp[j] + dp[i]) % mod;
    }
  }
  cout << dp[n - 1];
  return 0;
}
