Flux quantization and quantum mechanics on Riemann surfaces in an external magnetic field