# import sys
while True:
    try:
        s = input()
        N = int(input())
        counts = {}
        maxCount = 0
        res = ''
        #计算每个字符开头的N个字符的GC个数,如果更大就保存到最大的值里
        for i in range(len(s) - N + 1):
            com_s = s[i:i+N]
            count = com_s.count('C') + com_s.count('G')
            if count > maxCount:
                maxCount = count
                res = com_s
        print(res)
    except:
#         print(sys.exc_info())
        break