from sys import stdin n, m = [int(x) for x in stdin.readline().rstrip().split()] a = [int(x) for x in stdin.readline().rstrip().split()] b = [int(x) for x in stdin.readline().rstrip().split()] ab = [] for x in a: ab.append((x,0)) for x in b: ab.append((x,1)) ab.append((-10**10,0)) ab.append((10**10,0)) ab.sort() ans = 2*10**10 - 1 - n l = len(ab) rangemax = 0 for i in range(1,l): rangemax = max(rangemax,ab[i][0]-ab[i-1][0]) if ab[i][1] == 0: ans -= rangemax - 1 rangemax = 0 print("{}".format(ans))