# A - Frog 1

from collections import defaultdict





def main():

    N, *H = list(map(int, open(0).read().split()))

    H = [0] + H + [0, 0]

    dp = defaultdict(lambda: 1 << 30)

    dp[1] = 0

    for i, a in enumerate(H[1:N + 1], 1):

        for j, b in enumerate(H[i + 1:i + 3], i + 1):

            dp[j] = min(dp[j], dp[i] + abs(a - b))

    print((dp[N]))





if __name__ == "__main__":

    main()

# A - Frog 1

def main():

    N, *H = list(map(int, open(0).read().split()))

    H = [0] + H + [0, 0]

    dp = [1 << 30] * (N + 3)

    dp[1] = 0

    for i, a in enumerate(H[1:N + 1], 1):

        for j, b in enumerate(H[i + 1:i + 3], i + 1):

            dp[j] = min(dp[j], dp[i] + abs(a - b))

    print((dp[N]))





if __name__ == "__main__":

    main()

# A - Frog 1
from collections import defaultdict


def main():
    N, *H = list(map(int, open(0).read().split()))
    H = [0] + H + [0, 0]
    dp = defaultdict(lambda: 1 << 30)
    dp[1] = 0
    for i, a in enumerate(H[1 : N + 1], 1):
        for j, b in enumerate(H[i + 1 : i + 3], i + 1):
            dp[j] = min(dp[j], dp[i] + abs(a - b))
    print((dp[N]))


if __name__ == "__main__":
    main()

# A - Frog 1
def main():
    N, *H = list(map(int, open(0).read().split()))
    H = [0] + H + [0, 0]
    dp = [1 << 30] * (N + 3)
    dp[1] = 0
    for i, a in enumerate(H[1 : N + 1], 1):
        for j, b in enumerate(H[i + 1 : i + 3], i + 1):
            dp[j] = min(dp[j], dp[i] + abs(a - b))
    print((dp[N]))


if __name__ == "__main__":
    main()

-from collections import defaultdict - - -    dp = defaultdict(lambda: 1 << 30) +    dp = [1 << 30] * (N + 3)