output_description: Print the minimum cost required to unlock all the treasure boxes. If it is
  impossible to unlock all of them, print -1.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      N M
      a_1 b_1
      c_{11} c_{12} ... c_{1{b_1}}
      :
      a_M b_M
      c_{M1} c_{M2} ... c_{M{b_M}}
attempt: from fractions import gcd as bltin_gcd
  
  a, b = [int(x) for x in input().split()]
  
  d = 1
  d_list = []
  while d <= a and d <= b:
      if a % d == 0 and b % d == 0:
          d_list.append(d)
      d += 1
  
  count = 0
  length = len(d_list)
  
  answer = 0
  is_sosu = True
  for i in range(length):
      is_sosu = True
      for j in range(length):
          print(d_list[i], d_list[j], i == j, is_sosu, bltin_gcd(d_list[i], d_list[j]))
          if i != j:
              if bltin_gcd(d_list[i], d_list[j]) != 1:
                  is_sosu = False
                  length = len(d_list)
                  break
      if not is_sosu:
          answer += 1
  print(answer)
  
problem_description: Statement
  
  We have N locked treasure boxes, numbered 1 to N.
  
  A shop sells M keys. The i-th key is sold for a_i yen (the currency of Japan),
  and it can unlock b_i of the boxes: Box c_{i1}, c_{i2}, ..., c_{i{b_i}}. Each
  key purchased can be used any number of times.
  
  Find the minimum cost required to unlock all the treasure boxes. If it is
  impossible to unlock all of them, print -1.
samples: [{"input": "2 3\n    10 1\n    1\n    15 1\n    2\n    30 2\n    1 2", "output": "25\n    \n\nWe can unlock all the boxes by purchasing the first and second keys, at the\ncost of 25 yen, which is the minimum cost required.\n\n* * *"}, {"input": "12 1\n    100000 1\n    2", "output": "-1\n    \n\nWe cannot unlock all the boxes.\n\n* * *"}, {"input": "4 6\n    67786 3\n    1 3 4\n    3497 1\n    2\n    44908 3\n    2 3 4\n    2156 3\n    2 3 4\n    26230 1\n    2\n    86918 1\n    3", "output": "69942"}]