#include <bits/stdc++.h>
using namespace std;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const long long linf = 4000000000000000000LL;
const long long inf = 1000000007;
const long double pi = 3.1415926535;
void pv(vector<int> a) {
  for (auto& x : a) cout << x << " ";
  cout << '\n';
}
void pv(vector<long long> a) {
  for (auto& x : a) cout << x << " ";
  cout << '\n';
}
void pv(vector<vector<int>> a) {
  for (int i = (0); i < (int(a.size())); ++i) {
    cout << i << '\n';
    pv(a[i]);
    cout << '\n';
  }
}
void pv(vector<vector<long long>> a) {
  for (int i = (0); i < (int(a.size())); ++i) {
    cout << i << '\n';
    pv(a[i]);
  }
  cout << '\n';
}
void pv(vector<string> a) {
  for (auto& x : a) cout << x << '\n';
  cout << '\n';
}
void build_primes(vector<int>& primes, int size) {
  vector<int> visited;
  visited.resize(size, 0);
  for (int i = (2); i < (size); ++i) {
    if (visited[i] == 0) {
      primes.push_back(i);
      int a = i;
      while (a < size) {
        visited[a] = 1;
        a += i;
      }
    }
  }
}
vector<vector<long long>> matrix_mult(vector<vector<long long>>& a,
                                      vector<vector<long long>>& b) {
  int n = a.size();
  vector<vector<long long>> answer;
  answer.resize(n);
  for (int i = 0; i < n; i++) answer[i].resize(n, 0);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      for (int k = 0; k < n; k++)
        answer[i][j] = (answer[i][j] + a[i][k] * b[k][j]) % inf;
    }
  }
  return answer;
}
int modInverse(int a, int m) {
  int m0 = m;
  int y = 0, x = 1;
  if (m == 1) return 0;
  while (a > 1) {
    int q = a / m;
    int t = m;
    m = a % m, a = t;
    t = y;
    y = x - q * y;
    x = t;
  }
  if (x < 0) x += m0;
  return x;
}
long long power(long long x, long long y) {
  long long k = 1LL << 60;
  long long z = 1;
  while (k != 0) {
    z *= z;
    z %= inf;
    if (y >= k) {
      z *= x;
      z %= inf;
      y -= k;
    }
    k >>= 1;
  }
  return z;
}
struct point {
  long double x, y;
  bool operator<(const point& rhs) const {
    if (x == rhs.x) return y < rhs.y;
    return x < rhs.x;
  }
};
struct pt {
  long long x, y;
  bool operator<(const pt& rhs) const {
    if (x == rhs.x) return y < rhs.y;
    return x < rhs.x;
  }
};
long double area(point x, point y, point z) {
  return (x.y * y.x + y.y * z.x + z.y * x.x - x.x * y.y - y.x * z.y -
          z.x * x.y) /
         2.0;
}
bool clockwise(point x, point y, point z) { return area(x, y, z) > 0; }
long double area(pt x, pt y, pt z) {
  return (x.y * y.x + y.y * z.x + z.y * x.x - x.x * y.y - y.x * z.y -
          z.x * x.y) /
         2.0;
}
bool clockwise(pt x, pt y, pt z) { return area(x, y, z) > 0; }
long long gcd(long long a, long long b) {
  if (a > b) swap(a, b);
  if (a == 0) return b;
  return gcd(a, b % a);
}
int popcount(long long a) {
  int count = 0;
  while (a) {
    count += (a & 1);
    a >>= 1;
  }
  return count;
}
long long choose(long long n, long long r) {
  long long p = 1, k = 1;
  if (n - r < r) r = n - r;
  if (r != 0) {
    while (r) {
      p *= n;
      k *= r;
      long long m = gcd(p, k);
      p /= m;
      k /= m;
      n--;
      r--;
    }
  } else
    p = 1;
  return p;
}
vector<long long> prefix_hash(string& a, vector<long long>& powers,
                              long long mod) {
  int n = int(a.size());
  vector<long long> prefix(n + 1);
  for (int i = (0); i < (n); ++i)
    prefix[i + 1] = (prefix[i] + powers[i] * (a[i] - '1' + 1)) % mod;
  return prefix;
}
struct custom_hash {
  static uint64_t splitmix64(uint64_t x) {
    x += 0x9e3779b97f4a7c15;
    x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
    x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
    return x ^ (x >> 31);
  }
  uint64_t operator()(uint64_t x) const {
    static const uint64_t FIXED_RANDOM =
        chrono::steady_clock::now().time_since_epoch().count();
    return splitmix64(x + FIXED_RANDOM);
  }
};
struct custom_hash_fast {
  uint64_t operator()(uint64_t x) const {
    static const uint64_t FIXED_RANDOM =
        chrono::steady_clock::now().time_since_epoch().count();
    x ^= FIXED_RANDOM;
    return x ^ (x >> 16);
  }
};
void setIO(string second) {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  if (int(second.size())) {
    freopen((second + ".in").c_str(), "r", stdin);
    if (second != "test3") freopen((second + ".out").c_str(), "w", stdout);
  }
}
int n, k;
long long p;
vector<long long> a, b;
long long ans = linf;
void solve() {
  long long sum = 0;
  for (int i = (0); i < (n); ++i) {
    sum = max(sum, abs(a[i] - b[i]) + abs(p - b[i]));
  }
  ans = min(ans, sum);
}
int main() {
  setIO("");
  cin >> n >> k >> p;
  a.resize(n);
  for (auto& x : a) cin >> x;
  vector<long long> c(k);
  for (auto& x : c) cin >> x;
  sort(a.begin(), a.end());
  sort(c.begin(), c.end());
  for (int i = (0); i < (n); ++i) b.push_back(c[i]);
  for (int i = (0); i < (k - n); ++i) {
    solve();
    b.erase(b.begin());
    b.push_back(c[i + n]);
  }
  solve();
  cout << ans << '\n';
}
