#include <bits/stdc++.h>
using namespace std;
using llong = long long;
using PII = pair<int, int>;
const llong MOD = 998244353LL;
const double PI = acos(-1);
llong add(llong a, llong b) {
  a += b;
  if (a >= MOD) return a - MOD;
  return a;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  vector<llong> jump;
  for (int i = 0; i < k; i++) {
    int l, r;
    cin >> l >> r;
    for (int j = l; j <= r; j++) {
      jump.push_back(j);
    }
  }
  sort(jump.begin(), jump.end());
  vector<llong> dp(n);
  dp[0] = 1;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < jump.size(); j++) {
      if (i + jump[j] >= n) break;
      dp[i + jump[j]] = add(dp[i + jump[j]], dp[i]);
    }
  }
  cout << dp[n - 1];
}
