We establish a theory of Q-valued functions minimizing a suitable generalization of the Dirichlet integral. In a second paper the theory will be used to approximate efficiently area minimizing currents mod(p) when p=2Q, and to establish a first general partial regularity theorem for every p in any dimension and codimension.