#include <bits/stdc++.h>
struct city {
  city(std::int64_t x, std::int64_t y) : x(x), y(y) {}
  std::int64_t x;
  std::int64_t y;
};
inline bool operator<(city const& lhs, city const& rhs) {
  if (lhs.x < rhs.x) return true;
  if (rhs.x < lhs.x) return false;
  return lhs.y < rhs.y;
}
inline std::int64_t price(city const& lhs, city const& rhs) {
  return std::min(std::abs(lhs.x - rhs.x), std::abs(lhs.y - rhs.y));
}
std::int64_t solve(std::vector<city> cs) {
  std::int64_t num_of_roads = cs.size() - 1;
  std::sort(cs.begin(), cs.end());
  auto it = cs.begin();
  auto end = cs.end();
  auto min_total = std::numeric_limits<std::int64_t>::max();
  do {
    std::int64_t total = 0;
    for (std::int64_t i = 0; i != num_of_roads; ++i) {
      total += price(cs[i], cs[i + 1]);
    }
    if (total < min_total) min_total = total;
  } while (std::next_permutation(it, end));
  return min_total;
}
int main() {
  std::int64_t n;
  std::cin >> n;
  std::vector<city> cs;
  cs.reserve(n);
  for (std::int64_t i = 0; i != n; ++i) {
    std::int64_t xi, yi;
    std::cin >> xi >> yi;
    cs.emplace_back(xi, yi);
  }
  std::cout << solve(cs) << std::endl;
}
