Mateo walked 8 km and 570 m to the library and walked back 2 km and 824 m to his office. How much distance did he walk?