How does a mass spectrometer identify different molecules in a sample, and what are its applications in chemical analysis and molecular biology?