output_description: Print the minimum possible value of "the sum of the digits of A" plus "the sum
  of the digits of B".
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      N
attempt: N = int(input())
  LR = [tuple(map(int, input().split())) for i in [None] * N]
  Lmin = sorted(LR, key=lambda x: x[0])
  Rmax = sorted(LR, key=lambda x: x[1], reverse=True)
  
  T = 0
  
  
  def t_len(lr):
      a = lr[1] - T
      b = T - lr[0]
      return a if a > b else b
  
  
  def select(l):
      return sorted(l, key=t_len, reverse=True)[0]
  
  
  def select2(l):
      a = abs(Lmin[0][0] - T)
      b = abs(Rmax[0][1] - T)
      return Lmin[0] if a > b else Rmax[0]
  
  
  def selectT(lr):
      if lr[0] <= T <= lr[1]:
          return T
      a = lr[1] - T
      b = T - lr[0]
      return lr[0] if a > b else lr[1]
  
  
  K = 0
  for i in [None] * N:
      s = select2(LR)
      nextT = selectT(s)
      K += abs(nextT - T)
      T = nextT
      LR.remove(s)
      Lmin.remove(s)
      Rmax.remove(s)
  K += abs(T)
  print(K)
  
problem_description: Statement
  
  Takahashi has two positive integers A and B.
  
  It is known that A plus B equals N. Find the minimum possible value of "the
  sum of the digits of A" plus "the sum of the digits of B" (in base 10).
samples: [{"input": "15", "output": "6\n    \n\nWhen A=2 and B=13, the sums of their digits are 2 and 4, which minimizes the\nvalue in question.\n\n* * *"}, {"input": "100000", "output": "10"}]