#include <bits/stdc++.h>
using namespace std;
using pll = pair<long long, long long>;
using vl = vector<long long>;
using vpll = vector<pll>;
using mll = map<long long, long long>;
using mcl = map<char, long long>;
using msl = map<string, long long>;
using sl = set<long long>;
using sc = set<char>;
using dl = deque<long long>;
const int N = 1e6 + 5;
long long mod = 998244353;
vl adj[N];
vpll adjc[N];
long long vis[N];
long long arr[N];
long long csum(vector<long long>& nums, long long target) {
  long long dp[target + 1];
  memset(dp, 0, sizeof(dp));
  dp[0] = 1;
  for (long long i = 1; i <= target; i++) {
    for (long long j : nums)
      if (i >= j) dp[i] = ((dp[i] % mod) + (dp[i - j] % mod)) % mod;
  }
  return dp[target];
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long a, b, c, d, n, m, p, x, y, z, i, j, k,
      f = 0, tc, cnt = 0, sum = 0, mul = 1, mi = 1e18, ma = -1e18, cs;
  string str;
  char ch;
  double db;
  long long l, r;
  cin >> n >> x;
  vl vt;
  for (i = 0; i < x; i++) {
    cin >> l >> r;
    for (k = l; k <= r; k++) vt.push_back(k);
  }
  cout << csum(vt, n - 1) << "\n";
  return 0;
}
