import math

CON = 998244353

N, K = list(map(int,input().split()))
LR = [list(map(int,input().split())) for _ in range(K)]

dp = [0] * (N + 1)
fac = [None] * (N + 1)

# def calc(num):
#     i = 1
#     while num - i >= i:
#         if num - i == i:
#             dp[num] += (dp[num - 1 - i] ** fact(num - 1 - i) ) * (dp[i] ** fact(i))
#         else:
#             dp[num] += perm(num - 1 , (num - 1) - i, i) * ( dp[num - 1 - i] ** math.factorial(num - 1 - i) ) * (dp[i] ** math.factorial(i))
#         i += 1

def calc(num):
    for i in range(1, num//2 + 1):
        dp[num] += dp[num - i] * dp[i]

def perm(n,p,q):
    return fact(n) // ( fact(p) * fact(q) )


def solve():
    # dp初期設定
    for scp in LR:
        for pnt in range(scp[0],scp[1] + 1):
            dp[pnt] = 1
    
    for j in range(2,N + 1):
        calc(j)

    print(dp[N-1])


solve()