/// Swift5 -> Swift2.2
extension String {
    // split(separator:maxSplits:omittingEmptySubsequences:)
    func split(separator separator: Character) -> [String] {
        return self.characters.split(separator).map(String.init)
    }
}
extension Array {
    // init(repeating:count:)
    init(repeating: Element, count: Int) {
       self.init(count: count, repeatedValue: repeating)
    }
}
/// end

let N = Int(readLine()!)!
let h = [0] + readLine()!.split(separator: " ").map { Int($0)! }
var dp = Array(repeating: 0, count: N + 1)

for i in 1 ... N {
    switch i {
    case 1:
        continue
    case 2:
        dp[i] = abs(h[i] - h[i - 1])
    default:
        // Avoid "expression was too complex to be solved in reasonable time"
        let step1 = dp[i - 1] + abs(h[i] - h[i - 1])
        let step2 = dp[i - 2] + abs(h[i] - h[i - 2])
        dp[i] = min(step1, step2)
    }
}

print(dp.last!)
