1super_set=set(map(int,input().split()))
2count=True
3n=int(input())
4for i in range(n):
5 normal_set=set(map(int,input().split()))
6 if len(super_set)>len(normal_set):
7 if not super_set.issuperset(normal_set):
8 count=False
9print(count)