#include <bits/stdc++.h>
using namespace std;
long long n, m;
const long long N = 2e5 + 100;
const long long M = 15;
long long x[M], y[M];
long long k = 1;
long long f[N];
const long long MOD = 998244353;
signed main() {
  memset(f, 0, sizeof(f));
  cin >> n >> m;
  for (register long long a, b, i = 1; i <= m; i++) {
    cin >> x[i] >> y[i];
  }
  f[n] = 1;
  for (register long long i = n; i >= 1; i--)
    for (register long long j = 1; j <= m; j++)
      for (register long long k = x[j]; k <= y[j]; k++)
        if (i + k <= n)
          f[i] = (f[i] + f[i + k]) % MOD;
        else
          break;
  cout << f[1] << endl;
}
