Finds distance for the last element