nums=[int(x) for x in input().split(',')] num1=sorted(nums) if nums==num1 or len(nums)<=1: print(0) else: cur=nums[0] dp=[0]*len(nums) dp[0]=0 for i in range(1,len(nums)): dp[i]=max(dp[i-1],dp[i-1]-nums[i]+cur) cur=nums[i] print(dp[len(nums)-1])