import itertools inp1 = input().split() inp2 = input().split() seq= [] for s in inp2: seq.append(int(s)) allseq = list(itertools.permutations(seq)) anc = [] a = int(inp1[1]) for s in allseq: a = int(inp1[1]) for q in s: a = a % q anc.append(a) print(max(anc))