EDIT: In general relativity given a manifold $M$ one can consider a functional on (pseudo-) Riemannian metrics $g$ $$\int_M R\,\, dvol_g,$$ where $R$ is the scalar curvature and $vol_g$ is the (pseudo-) Riemannian measure. The extremal metrics for this functional (solutions of the Euler-Lagrange equation) satisfy the so called Einstein equation.
As far as I heard the distinguished property of the above functional is that $R$ involves second derivatives of the metric, but the Euler-Lagrange equation is a differential equation not of the fourth order in the metric, but only of the second order in the metric.
I am looking for a precise statement within what class of functionals on metrics the above property distinguishes the scalar curvature $R$. Say assume I have a generally covariant expression involving at most second order derivatives of the metric such that the Euler-Lagrange equation is also of second order in the metric. Does it imply that this expression is proportional to $R$?