The converse theorem for automorphic representations