#include <bits/stdc++.h>
using namespace std;
long long MOD = 1000000007;
long long INF = 1e18;
void solve() {
  int n, k;
  int m = 998244353;
  cin >> n >> k;
  int arr[k][2];
  vector<int> dp(n + 1, 0), pre(n + 2, 0);
  for (int i = 0; i < k; i++) {
    cin >> arr[i][0] >> arr[i][1];
  }
  dp[1] = pre[1] = 1;
  int l, r;
  for (int i = 2; i <= n; i++) {
    for (int j = 0; j < k; j++) {
      if (i < arr[j][0]) continue;
      l = arr[j][0];
      r = min(arr[j][1], i - 1);
      dp[i] = (dp[i] + pre[i - l] - pre[i - r - 1] + m) % m;
    }
    pre[i] = (pre[i - 1] + dp[i]) % m;
  }
  cout << dp[n];
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  int test;
  test = 1;
  for (int t = 1; t <= test; t++) {
    solve();
  }
  return 0;
}
