Catalysis of the oxidative demethylation of N1-methyladenine and N3-methylcytosine in DNA and RNA, with concomitant decarboxylation of 2-oxoglutarate and releases oxidized methyl group on N1-methyladenine and N3-methylcytosine as formaldehyde.