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())
  a = list(map(int, input().split()))
  a.sort(reverse=True)
  num = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
  canmake = dict()
  b = []
  for i in a:
      b.append(num[i])
      if num[i] not in canmake.keys():
          canmake[num[i]] = i
  b.sort()
  c = []
  d = []
  amari = n % b[0]
  longest = n // b[0]
  if amari == 0:
      print(str(b[0]) * (n // b[0]))
  # 何ケタ減らすと丁度になるか求める
  for i in range(1, len(b)):
      count = 0
      now = amari
      while True:
          count += 1
          now += b[0]
          if count > b[i]:
              break
          if now % b[i] == 0:
              c.append(count - now // b[i])
              d.append((count, now // b[i], b[i]))
              break
  res = min(c)
  ans = []
  for i in range(c.count(res)):
      an = dict()
      idx = c.index(res)
      an[b[0]] = longest - d[idx][0]
      an[d[idx][2]] = d[idx][1]
      ans.append(an)
      c[idx] = -1
  
  result = 0
  for i in ans:
      x = []
      for i in an.keys():
          x.append((canmake[i], an[i]))
      x.sort(key=lambda y: y[0])
      re = ""
      for i in range(len(x)):
          y = x.pop()
          re += str(y[0]) * y[1]
      ima = int(re)
      if ima > result:
          result = ima
  
  if amari != 0:
      print(result)
  
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."}]