l = input()
N = int(l.split(" ")[0])
K = int(l.split(" ")[1])


ll = [input() for i in range(K)]

a_list = []
for llel in ll:
    a_list += list(range(int(llel.split(" ")[0]), int(llel.split(" ")[1])+1))

a_list.sort()
#print(a_list)

e = [0] * len(a_list)
maxe = [0] * len(a_list)
for i in range(len(a_list)):
    if (N-1) % a_list[i] == 0:
        maxe[i] = (N-1) // a_list[i]
    else:
        maxe[i] = (N - 2) // a_list[i]

#print(e)
##print(maxe)

def ddot():
    dp = 0
    for i in range(len(e)):
        dp += e[i] * a_list[i]
    return dp

ans = 0
while(True):
    ddd = ddot()
    if ddd == N - 1:
        ans += 1
    #print(str(e) + " " + str(ddd))
    for i in range(len(e)):
        if e[i] < maxe[i]:
            e[i] += 1
            break
        else:
            if i == len(e) - 1:
                # true end
                print(ans)
                quit()
                break
            else:
                e[i] = 0

#print(ans)