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: INF = float("inf")
  n, m = map(int, input().split())
  a = list(map(int, input().split()))
  cost = [2, 5, 5, 4, 5, 6, 3, 7, 6]
  l = [[x, cost[x - 1]] for x in a]
  l = sorted(l, key=lambda x: x[1] * 10 - x[0])
  r = l[0]
  k = max((n - 210), 0) // r[1]
  n -= r[1] * k
  _max = [0] + [-INF] * n
  for i in range(1, n + 1):
      for x in l:
          if x[1] <= i:
              _max[i] = max(_max[i], _max[i - x[1]] * 10 + x[0])
  ans = str(_max[n]) + str(r[0]) * k
  print(ans)
  
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."}]