Buggy python submission (verdict: Time Limit Exceeded):
from copy import deepcopy


def solve(road, num, ans, n):
    pattern = 0
    test = deepcopy(road)
    if ans.count(str(num)) > 1:
        return 0
    if len(ans) is n:
        return 1
    if len(road[num - 1]) == int(0):
        return 0
    else:
        for i in range(len(road[num - 1])):
            tmp = test[num - 1][-1]
            if tmp is not 0:
                word = ans + str(tmp)
            test[num - 1].pop()
            pattern += solve(test, tmp, word, n)
    return pattern


N, M = [int(i) for i in input().split()]
town = []
for i in range(N):
    town.append(deepcopy([]))

for i in range(M):
    a, b = [int(i) for i in input().split()]
    town[a - 1].append(b)
    town[b - 1].append(a)
print(solve(town, 1, '1', N))


Fixed submission:
from copy import deepcopy


def solve(road, num, ans, n):
    pattern = 0
    test = deepcopy(road)
    for s in test:
        if num in s:
            s.remove(num)
    if len(ans) is n:
        return 1
    if len(test[num - 1]) == int(0):
        return 0
    else:
        for i in range(len(test[num - 1])):
            tmp = test[num - 1][i]
            if tmp is not 0:
                word = ans + str(tmp)
            pattern += solve(test, tmp, word, n)
    return pattern


N, M = [int(i) for i in input().split()]
town = []
for i in range(N):
    town.append(deepcopy([]))

for i in range(M):
    a, b = [int(i) for i in input().split()]
    if a is not 1 or b is not 1:
        town[a - 1].append(b)
        town[b - 1].append(a)
print(solve(town, 1, '1', N))

Buggy python submission (verdict: Time Limit Exceeded):
from copy import deepcopy


def solve(road, num, ans, n):
    pattern = 0
    test = deepcopy(road)
    if ans.count(str(num)) > 1:
        return 0
    if len(ans) is n:
        return 1
    if len(road[num - 1]) == int(0):
        return 0
    else:
        for i in range(len(road[num - 1])):
            tmp = test[num - 1][0]
            if tmp is not 0:
                word = ans + str(tmp)
            test[num - 1].pop(0)
            pattern += solve(test, tmp, word, n)
    return pattern


N, M = [int(i) for i in input().split()]
town = []
for i in range(N):
    town.append(deepcopy([]))

for i in range(M):
    a, b = [int(i) for i in input().split()]
    town[a - 1].append(b)
    town[b - 1].append(a)
print(solve(town, 1, '1', N))


Fixed submission:
from copy import deepcopy


def solve(road, num, ans, n):
    pattern = 0
    test = deepcopy(road)
    for s in test:
        if num in s:
            s.remove(num)
    if len(ans) is n:
        return 1
    if len(test[num - 1]) == int(0):
        return 0
    else:
        for i in range(len(test[num - 1])):
            tmp = test[num - 1][i]
            if tmp is not 0:
                word = ans + str(tmp)
            pattern += solve(test, tmp, word, n)
    return pattern


N, M = [int(i) for i in input().split()]
town = []
for i in range(N):
    town.append(deepcopy([]))

for i in range(M):
    a, b = [int(i) for i in input().split()]
    if a is not 1 or b is not 1:
        town[a - 1].append(b)
        town[b - 1].append(a)
print(solve(town, 1, '1', N))

Buggy python submission (verdict: Time Limit Exceeded):
from copy import deepcopy


def solve(road, num, ans, n):
    pattern = 0
    test = deepcopy(road)
    if len(ans) is int(n):
        for i in range(1, n + 1):
            if ans.count(str(i)) == 0:
                return 0
        return 1
    if len(road[num - 1]) == int(0):
        return 0
    else:
        for i in range(len(road[num - 1])):
            tmp = test[num - 1][0]
            if tmp is not 0:
                word = ans + str(tmp)
            test[num - 1].pop(0)
            pattern += solve(test, tmp, word, n)
    return pattern


N, M = [int(i) for i in input().split()]
town = []
for i in range(N):
    town.append(deepcopy([]))

for i in range(M):
    a, b = [int(i) for i in input().split()]
    town[a - 1].append(b)
    town[b - 1].append(a)
print(solve(town, 1, '1', N))


Fixed submission:
from copy import deepcopy


def solve(road, num, ans, n):
    pattern = 0
    test = deepcopy(road)
    for s in test:
        if num in s:
            s.remove(num)
    if len(ans) is n:
        return 1
    if len(test[num - 1]) == int(0):
        return 0
    else:
        for i in range(len(test[num - 1])):
            tmp = test[num - 1][i]
            if tmp is not 0:
                word = ans + str(tmp)
            pattern += solve(test, tmp, word, n)
    return pattern


N, M = [int(i) for i in input().split()]
town = []
for i in range(N):
    town.append(deepcopy([]))

for i in range(M):
    a, b = [int(i) for i in input().split()]
    if a is not 1 or b is not 1:
        town[a - 1].append(b)
        town[b - 1].append(a)
print(solve(town, 1, '1', N))