Measurement of the isotopic composition of hydrogen and helium nuclei in cosmic rays with the PAMELA experiment