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()))
  honsuu = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
  aval = []
  for a in A:
      aval += [honsuu[a]]
  aval.sort()
  
  dp = [0]
  # i 本のマッチで作れる最高の桁数
  for i in range(1, N + 1):
      for b in aval:
          if i < b:
              continue
          else:
              dp += [dp[i - b] + 1]
              break
      else:
          dp += [0]
  
  # 作れる桁数はdp[-1]=dp[N] で, 最高桁にi が使えるかどうかの条件は,
  # a in A かつ dp[N- honsuu[a]] = dp[N] -1
  A.sort(reverse=True)
  ans = []
  for i in range(dp[N], 1, -1):
      for a in A:
          if N - honsuu[a] < 0:
              continue
          if dp[N - honsuu[a]] == dp[N] - 1:
              N -= honsuu[a]
              ans += [a]
              break
  
  final = 0
  for i in range(10):
      if i in A and honsuu[i] == N:
          final = i
          break
  ans += [final]
  print("".join(map(str, 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."}]