General introduction to cosmology of modified gravity is given. It is shown that different forms of modified gravity are possible: many of them being consistent with Solar system tests and cosmological bounds. Special attention is paid to F(R) gravity. It is shown that such theory may naturally describe the early-time inflation with late-time acceleration (dark energy epoch). Realistic versions of F(R) gravity are proposed. The inflationary indices are shown to be consistent with Planck experiment. New ghost-free versions of modified gravity are introduced and their cosmological evolution is studied. It is shown that it may naturally give the unification of inflation with dark energy while scalar field which appears there plays the role of dark matter.