This is a book that haunted me for years.
A girl lives on a very low level of an ant-hill-like society where most people live underground (supposedly due to a polluted surface). Most of the people around her are bred to be low-intelligence or are possibly the descendants of political prisoners. She is intelligent so she often gets in trouble. The levels of the underground world correspond to a class system, with the aristocracy living on the highest levels. There is a classroom scene where she is forced to watch videos over and over about how to tie her shoes.
A boy mysteriously shows up from the surface of the planet (his parents are farmers?) and together they escape to the surface and she learns everything she has been told is wrong and she was actually part of a subterranean slave society.
Ring any bells?