Superpotentials of N=1 supersymmetric gauge theories from M-theory