N, L = list(map(int, input().strip().split())) X = list(map(int, input().strip().split())) Y = list(map(int, input().strip().split())) C = [0 for i in range(L+1)] for x in X: C[x] = 2 for y in Y: C[y] = 3 S = [0 for i in range(L+1)] last = -1 count = 0 for i in range(L+1, 0, -1): if C[i-1] != 0: count = int(C[i-1] == last) * count + 1 last = C[i-1] S[i-1] = count ind = 0 m = 0 for i in range(L+1): if S[i] >= m and C[i] != 0: ind = i m = S[i] print(max(S) * L + ind)