import string P = int(input()) B = int(input()) def hash(S): res = 0 for s in S: res = (res * B + s) % P return res D1 = {'': 0} D2 = {} def dfs(s): v = (D1[s[:-1]] + ord(s[-1])) % P D1[s] = v if v in D2: print(s) print(D2[v]) exit() else: D2[v] = s if len(s) == 10**4: return for c in string.ascii_lowercase: dfs(s+c) for c in string.ascii_lowercase: dfs(c)