N = int(input()) A = list(map(int, input().split())) DP = [-10**18,-10**18] for i,a in enumerate(A): NDP = [max(DP[0],DP[1]+a) ,max(DP[1],DP[0]-a)] DP = NDP if DP[1]<-a: NDP[1]=-a print(max(DP))