






import os


def 	lowerCamelCase__      (  lowercase = "input.txt"					):

  """simple docstring"""






  with open(os.path.join(os.path.dirname(lowercase					)    ,  lowercase					)					) as input_file:
    SCREAMING_SNAKE_CASE							:   List[str]						    =     [
        [int(lowercase					) for element in line.split(","					)]
        for line in input_file.readlines()
    ]

  SCREAMING_SNAKE_CASE							:   Optional[Any]						    =     len(lowercase					)
  SCREAMING_SNAKE_CASE							:   Dict						    =     len(matrix[0]					)

  SCREAMING_SNAKE_CASE							:   Dict						    =     [[-1 for _ in range(lowercase					)] for _ in range(lowercase					)]
  for i in range(lowercase					):
    SCREAMING_SNAKE_CASE							:   List[Any]						    =     matrix[i][0]

  for j in range(1    ,  lowercase					):
    for i in range(lowercase					):
      SCREAMING_SNAKE_CASE							:   List[str]						    =     minimal_path_sums[i][j - 1] + matrix[i][j]

    for i in range(1    ,  lowercase					):
      SCREAMING_SNAKE_CASE							:   Optional[int]						    =     min(
          minimal_path_sums[i][j]    ,  minimal_path_sums[i - 1][j] + matrix[i][j]					)

    for i in range(rows - 2    ,  -1    ,  -1					):
      SCREAMING_SNAKE_CASE							:   List[str]						    =     min(
          minimal_path_sums[i][j]    ,  minimal_path_sums[i + 1][j] + matrix[i][j]					)

  return min(minimal_path_sums_row[-1] for minimal_path_sums_row in minimal_path_sums					)


if __name__ == "__main__":
   print(F"""{solution() = }""")








"""simple docstring"""



def 			_UpperCamelCase						(    _A = 1_0_0_0   )     ->	int:





    """simple docstring"""

    _UpperCAmelCase     ,_UpperCAmelCase        = 1, 1
    _UpperCAmelCase        = 2
    while True:
        _UpperCAmelCase        = 0
        _UpperCAmelCase        = fa + fa
        _UpperCAmelCase     ,_UpperCAmelCase        = fa, f
        index += 1
        for _ in str(_A   ):
            i += 1
        if i == n:
            break
    return index


if __name__ == "__main__":
 print(solution(int(str(input()).strip())))