n, d = map(int, input().split()) P = [list(map(int, input().split())) for _ in range(n)] Plus = [] Zero = [] Nega = [] for i in range(n): if P[i][0] <= P[i][1]: Plus.append(P[i]) elif P[i][0] == P[i][1]: Zero.append(P[i]) else: Nega.append(P[i]) if len(Plus) >= 2: Plus.sort(key=lambda x: x[0]) print(min(-Plus[0][0], -Plus[0][0] + Plus[0][1] - Plus[1][0])) elif len(Plus) == 1: if len(Zero) >= 1: Zero.sort(key=lambda x: x[0]) print(max(-Plus[0][0], -Zero[0][0])) else: Nega.sort(key=lambda x: x[1] - x[0], reverse=True) print((-Nega[0][0] + Nega[0][1]) * (n // 2)) else: Nega.sort(key=lambda x: x[1] - x[0], reverse=True) print((-Nega[0][0] + Nega[0][1]) * (n - n // 2) + \ (-Nega[1][0] + Nega[1][1]) * (n // 2))