1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# 6 10
# 3
# 1 3 6
#
# 60
#
# - - - - - -
#           |
#           |
#           |
#           |
#           |
#           |
#           |
#
#
#
#
#
# 4  10
#
# toFind = 40
#
# 2 4     8 16
#
# 6 10
#
# 1 3 6


w, h = map(int, input().split())
count = int(input())
dimensions = list(map(int, input().split()))

dimensionStart = min(w, h)
areaToFind = w * h
currentIndex = len(dimensions) - 1
result = 0

while currentIndex >= 0:
    dimension = dimensions[currentIndex]
    if dimension > dimensionStart or dimensionStart % dimension != 0:
        currentIndex -= 1
    else:
        area = dimension * dimension
        if area <= areaToFind:
            areaToFind -= area
            result += 1
        else:
            currentIndex -= 1

if result == 0:
    print(-1)
else:
    print(result)