#include <bits/stdc++.h>
using namespace std;
const int N = 200010;
const long long MOD = 998244353;
int n, k;
long long dp[N];
struct node {
  int l, r;
} a[N];
int main() {
  ios::sync_with_stdio(false);
  cin.tie();
  cout.tie(0);
  cin >> n >> k;
  int minpos = 1e9;
  for (int i = 1; i <= k; i++) {
    cin >> a[i].l >> a[i].r;
    minpos = min(minpos, a[i].l);
  }
  dp[1] = 1;
  for (int i = 2; i <= minpos; i++) dp[i] = 0;
  for (int i = 1 + minpos; i <= n; i++) {
    for (int j = 1; j <= k; j++) {
      for (int m = a[j].l; m <= a[j].r; m++) {
        dp[i] = (dp[i] + dp[max(i - m, 0)]) % MOD;
      }
    }
  }
  cout << (dp[n] + MOD) % MOD << '\n';
  return 0;
}
