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