input: from typing import List
  
  
  def closest_num(arr: List[int], num: int) -> int:
      """ Given an array of integers and a target integer, find the closest value to the target in the array.
      >>> closest_num([5, 4, 8, 7], 5)
      5
      >>> closest_num([1, 3, 6, 10], 4)
      3
      >>> closest_num([2, 4, 7, 11], 9)
      11
      """
output:     closest = arr[0]
      min_diff = abs(num - arr[0])
      
      for n in arr:
          diff = abs(num - n)
          if diff < min_diff:
              min_diff = diff
              closest = n
          elif diff == min_diff and n < closest:
              closest = n
      
      return closest