fav = int(input())
games = int(input())
inputs = []
scores = [0, 0, 0, 0]
remaining = [[1,2], [1,3], [1,4], [2,3], [2,4], [3,4]]

for i in range(games):
    inputs.append(list(map(int, input().split(" "))))
    temp = [inputs[-1][0], inputs[-1][1]]
    if temp in remaining:
        remaining.remove(temp)
    if temp[::-1] in remaining:
        remaining.remove(temp)
    if (inputs[-1][2] > inputs[-1][3]):
        scores[inputs[-1][0] -1] += 3
    elif (inputs[-1][2] < inputs[-1][3]):
        scores[inputs[-1][1] -1] += 3
    else:
        scores[inputs[-1][0] -1] += 1
        scores[inputs[-1][1] -1] += 1

def recursion(remaining, scores, fav):
    if len(remaining) == 0:
        if scores[fav-1] == max(scores):
            for i in range(4):
                if i != fav-1 and scores[i] == scores[fav-1]:
                    return 0
            return 1
        return 0
    temp1 = scores[:] 
    temp2 = scores[:] 
    temp3 = scores[:]
    temp1[remaining[0][0]-1] += 3 
    temp2[remaining[0][1]-1] += 3 
    temp3[remaining[0][0]-1] += 1 
    temp3[remaining[0][1]-1] += 1 
    return (recursion(remaining[1:], temp1, fav) + recursion(remaining[1:], temp2, fav) + recursion(remaining[1:], temp3, fav))

print(recursion(remaining, scores, fav))