CF242C King's Path

Description

The black king is standing on a chess field consisting of $ 10^{9} $ rows and $ 10^{9} $ columns. We will consider the rows of the field numbered with integers from $ 1 $ to $ 10^{9} $ from top to bottom. The columns are similarly numbered with integers from $ 1 $ to $ 10^{9} $ from left to right. We will denote a cell of the field that is located in the $ i $ -th row and $ j $ -th column as $ (i,j) $ . You know that some squares of the given chess field are allowed. All allowed cells of the chess field are given as $ n $ segments. Each segment is described by three integers $ r_{i},a_{i},b_{i} $ $ (a_{i}

Input Format

The first line contains four space-separated integers $ x_{0},y_{0},x_{1},y_{1} $ $ (1

Output Format

If there is no path between the initial and final position along allowed cells, print -1. Otherwise print a single integer — the minimum number of moves the king needs to get from the initial position to the final one.