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 = list(map(int, input().split()))
  
  items = {1: 2, 2: 5, 3: 5, 4: 4, 5: 5, 6: 6, 7: 3, 8: 7, 9: 6}
  dp = [0] * (N + 1)
  
  b_list = []
  for a in a_list:
      need = items[a]
      if need <= N:
          dp[need] = a
          b_list.append(a)
  
  M = len(b_list)
  b_list.sort()
  for i in range(N + 1):
      for b in b_list:
          if i - items[b] >= 0:
              if dp[i - items[b]] != 0:
                  cnt = 0
                  num = dp[i - items[b]]
                  while num >= 1:
                      cnt += 1
                      num //= 10
                  tmp = max(b * (10**cnt) + dp[i - items[b]], dp[i - items[b]] * 10 + b)
                  dp[i] = max(tmp, dp[i])
  print(dp[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."}]