n=gets.to_i s=gets.chomp q=s.count(?Q) w=(q**0.5).to_i if q==0 || q!=w**2 || n%w>0 ||s[/[H9]/] puts -1 exit end t=s.scan(/.{1,#{n/w}}/).sort if t[0]!=t[t.size-1] puts -1 else puts t[0] end