mod = 998244353
n, k = map(int, input().split())
lr = [list(map(int, input().split())) for i in range(k)]
dp = [0 for i in range(n + 1)]
dp[0] = 1
cum = [0, 1]
cur = [0 for i in range(k)]
for i in range(1, n + 1):
    cnt = 0
    for j in range(k):
        r = (i - (lr[j][1] - lr[j][0] + 1))
        l = r - (lr[j][1] - lr[j][0])
        print(l, r, cum)
        if l <= 0:
            continue
        cnt += cum[r] - cum[l - 1]
    dp[i] = dp[i - 1] + cnt
    cum.append(cnt + cum[-1])
print(dp[n])