import numpy as np

MOD = 998244353

def fft_convolve(f, g):
  Lf, Lg = f.shape[-1], g.shape[-1]
  L = Lf + Lg - 1
  fft_len = 1 << L.bit_length()
  fh, fl = f >> 15, f & (1 << 15) - 1
  gh, gl = g >> 15, g & (1 << 15) - 1
  def conv(f, g):
    Ff = np.fft.rfft(f, fft_len)
    Fg = np.fft.rfft(g, fft_len)
    h = np.fft.irfft(Ff * Fg)
    return np.rint(h)[..., :L].astype(np.int64) % MOD
  x = conv(fl, gl)
  z = conv(fh, gh)
  y = conv(fl + fh, gl + gh) - x - z
  return (x + (y << 15) + (z << 30)) % MOD

def coef_of_generating_function(P, Q, N):
  assert Q[0] == 1 and len(Q) == len(P) + 1
  def convolve(f, g):
    return fft_convolve(f, g)
  while N:
    Q1 = np.empty_like(Q)
    Q1[::2] = Q[::2]
    Q1[1::2] = MOD - Q[1::2]
    P = convolve(P, Q1)[N & 1::2]
    Q = convolve(Q, Q1)[::2]
    N >>= 1
  return P[0]

N, K = map(int, input().split())
Q = np.array([0]*(N+2), np.int64)
Q[0] = 1
Q[1] = -1
for _ in range(K):
  L, R = map(int, input().split())
  Q[L] -= 1
  Q[R+1] += 1

P = np.zeros_like(Q)[:-1]
P[0] = 1
P[1] = -1

print(coef_of_generating_function(P, Q, N-1))