m = 8; n = 1; i = 0; happynumbers = {}; While[n <= m, i++; If[HappyQ[i], n++; AppendTo[happynumbers, i] ] ] happynumbers