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: import sys
  
  sys.setrecursionlimit(999999)
  dicte = {1: 2, 2: 5, 3: 5, 4: 4, 5: 5, 6: 6, 7: 3, 8: 7, 9: 6}
  n, m = map(int, input().split())
  arr = list(map(int, input().split()))
  dp = [-1 for i in range(n + 1)]
  
  
  def cast(a, b):
      return int(str(a) + str(b))
  
  
  def solve(curn):
      maxi = -1
      if dp[curn] != -1:
          return dp[curn]
  
      for j in arr:
          if curn - dicte[j] >= 0:
              dp[curn - dicte[j]] = solve(curn - dicte[j])
              if dp[curn - dicte[j]] == None:
                  maxi = max(j, maxi)
              else:
                  maxi = max(cast(j, dp[curn - dicte[j]]), maxi)
      if maxi == -1:
          return None
      return maxi
  
  
  print(solve(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."}]