n = int(input()) s = input() x = 0 ng = False for c in s: if c == 'Q': x += 1 if c == 'H' or c == '9': ng = True if x == 1 and not ng: print(s) else: print(-1)