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()))
  dp = [False for i in range(N + 10)]
  memo = [[] for i in range(N + 10)]
  taiou = [[1, 2], [2, 5], [3, 5], [4, 4], [5, 5], [6, 6], [7, 3], [8, 7], [9, 6]]
  matchi = []
  for i in range(1, 10):
      if i in A:
          matchi.append(taiou[i - 1])
  matchi = sorted(matchi, key=lambda x: -x[0])
  matchi = sorted(matchi, key=lambda x: x[1])
  # for i in range(1,len(matchi)):
  #     if matchi[i][1] == matchi[i-1][1]:
  
  minma = matchi[0][1]
  # print(matchi)
  # print(minma)
  # dp[0] = F
  for i in range(len(matchi)):
      dp[matchi[i][1]] = True
      memo[matchi[i][1]].append(matchi[i][0])
  for i in range(N):
      for j in range(len(matchi)):
          if dp[i - matchi[j][1]]:
              dp[i] = True
              memo[i] = memo[i] + memo[i - matchi[j][1]]
              memo[i].append(matchi[j][0])
              break
  # print(dp)
  # print(memo)
  maxi = N
  for i in range(N // minma, 0, -1):
      if dp[N - i * minma]:
          maxi = i
          # print(maxi)
          break
  
  ans = sorted([matchi[0][0]] * maxi + memo[N - maxi * minma], reverse=True)
  for i in range(len(ans)):
      print(ans[i], sep="", end="")
  print("")
  
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."}]