Obama flies to Afghanistan, signs pact with Karzai