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