#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
void yes() {
  cout << "YES\n";
  return;
}
void no() {
  cout << "NO\n";
  return;
}
const long long int MOD = 998244353, mxN = 2e5 + 1;
vector<pair<int, int> > v;
long long int dp[mxN], ps[mxN];
void init() {}
void solve(int case_no) {
  int n, k;
  cin >> n >> k;
  for (int i = 0; i < k; i++) {
    int x, y;
    cin >> x >> y;
    v.emplace_back(x, y);
  }
  dp[1] = 1;
  ps[1] = 1;
  for (int i = 2; i <= n; i++) {
    for (pair<int, int> p : v) {
      dp[i] += ps[max(0, i - p.first)] - ps[max(0, i - p.second - 1)];
      dp[i] %= MOD;
    }
    ps[i] = ps[i - 1] + dp[i];
    ps[i] %= MOD;
  }
  cout << dp[n] << endl;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  srand(time(NULL));
  init();
  int t = 1;
  for (int i = 1; i <= t; i++) solve(i);
}
