code: def ordered_digits(number):
      n = len(number)
      dp = [[0 for j in range(10)] for i in range(2)]
  
      for i in range(n):
          min_prev = float("inf")
          for j in range(10):
              # find the min value from the previous digit and add it to the current value
              min_prev = min(min_prev, dp[(i - 1) % 2][j])
              # compute diff between the current digit and wanted digit
              diff = abs(j - int(number[i]))
              dp[i % 2][j] = min(diff, 10 - diff) + min_prev
  
      # min value from the last digit
      return min(dp[(n - 1) % 2])
  
label_desc: Use image node_id 1 for calling a global function with example usage: ordered_digits(number) and returns: min