#include <bits/stdc++.h>
using namespace std;
const long long losn = 1e6 + 5;
const long long maxn = 1e5 + 5;
const long long minn = 1e3 + 5;
const long long tiny = 1e2 + 5;
const long long inf = 1e9;
const long long mod = 1e9 + 7;
const long long hmod = 4698571;
long long u[11], v[11];
long long tot = 0;
long long dp[losn];
long long mods = 998244353;
long long vis[maxn * 2];
int main() {
  long long n, k;
  cin >> n >> k;
  for (long long i = 1; i <= k; i++) {
    cin >> u[i] >> v[i];
  }
  dp[1] = 1;
  for (long long i = 1; i <= n; i++) {
    for (long long j = 1; j <= k; j++) {
      if (u[j] >= i) continue;
      for (long long l = u[j]; l <= v[j]; l++) {
        if (i - l >= 1) {
          dp[i] += dp[i - l];
          dp[i] %= mods;
        } else {
          break;
        }
      }
    }
  }
  cout << dp[n] % mods << endl;
  return 0;
}
