output_description: If A is a divisor of B, print A + B; otherwise, print B - A.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      A B
attempt: n, m = map(int, input().split(" "))
  ai = list(sorted(map(int, input().split(" "))))
  required_maches = {1: 2, 2: 5, 3: 5, 4: 4, 5: 5, 6: 6, 7: 3, 8: 7, 9: 6}
  
  used_numbers = dict()
  
  
  def evaluate(l):
      if l == None:
          return -9999999999999999999999999999999
      if l == []:
          return 0
      return int("".join(reversed([str(i) for i in sorted(l)])))
  
  
  min_maches = min([required_maches[x] for x in ai])
  
  
  def find(matches_count_to_use):
      if matches_count_to_use not in used_numbers:
          if matches_count_to_use < 0:
              used_numbers[matches_count_to_use] = None
          elif matches_count_to_use == 0:
              used_numbers[matches_count_to_use] = []
          else:
              candidates = list(
                  filter(
                      lambda x: find(matches_count_to_use - required_maches[x]) != None,
                      ai,
                  )
              )
              if len(candidates) == 0:
                  used_numbers[matches_count_to_use] = None
              else:
                  number_to_use = max(
                      candidates,
                      key=lambda x: evaluate(
                          find(matches_count_to_use - required_maches[x]) + [x]
                      ),
                  )
                  prev = find(matches_count_to_use - required_maches[number_to_use])
                  used_numbers[matches_count_to_use] = prev + [number_to_use]
  
      return used_numbers[matches_count_to_use]
  
  
  print(evaluate(find(n)))
  
problem_description: Statement
  
  You are given positive integers A and B.
  
  If A is a divisor of B, print A + B; otherwise, print B - A.
samples: [{"input": "4 12", "output": "16\n    \n\nAs 4 is a divisor of 12, 4 + 12 = 16 should be printed.\n\n* * *"}, {"input": "8 20", "output": "12\n    \n\n* * *"}, {"input": "1 1", "output": "2\n    \n\n1 is a divisor of 1."}]