Hamiltonian Formulation of f (Riemann) Theories of Gravity