#include <bits/stdc++.h>
using namespace std;
const long long int maxx = 3 * 1e5, limit = 9 * 1e18, MOD = 998244353;
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long int n, k;
  cin >> n >> k;
  set<long long int> s;
  for (long long int i = 0; i < k; i++) {
    long long int a, b;
    cin >> a >> b;
    for (long long int i = a; i <= b; i++) {
      s.insert(i);
    }
  }
  long long int dp[n + 2];
  memset(dp, 0, sizeof(dp));
  ;
  dp[1] = 1;
  dp[0] = 0;
  for (long long int i = 2; i <= n; i++) {
    for (auto x : s) {
      if (x > i) break;
      dp[i] = (dp[i - x] + dp[i]) % MOD;
    }
  }
  cout << dp[n] << '\n';
  ;
}
