AstroM$^3$: A self-supervised multimodal model for astronomy