#include <bits/stdc++.h>
using namespace std;
long long dx[] = {1, -1, 0, 0, 1, 1, -1, -1};
long long dy[] = {0, 0, 1, -1, 1, -1, 1, -1};
const long long MAX = 2e5, mod = 998244353;
long long n, k, a, b, dp[MAX];
vector<long long> v;
long long f(long long x) {
  if (x > n) return 0;
  long long& ret = dp[x];
  if (ret != -1) return ret;
  ret = 0;
  for (long long i : v) {
    ret += f(x + i);
    ret %= mod;
  }
  return ret;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  ;
  memset(dp, -1, sizeof(dp));
  ;
  cin >> n >> k;
  for (long long i = 0; i < k; i++) {
    cin >> a >> b;
    for (long long i = a; i <= b; i++) v.push_back(i);
  }
  dp[n - 1] = 1;
  for (long long i = 0; i < n; i++) f(i);
  cout << f(0);
}
