#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pdd = pair<double, double>;
template <typename T>
using vec = vector<T>;
template <typename T>
using Prior = priority_queue<T>;
template <typename T>
using prior = priority_queue<T, vec<T>, greater<T>>;
const int INF = 0x3f3f3f3f;
const ll LLINF = 0x3f3f3f3f3f3f3f3f;
const ll MOD = 998244353;
const double PI = 3.14159265358;
const double EPS = 1e-8;
const int xx[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int yy[8] = {1, 0, -1, 0, 1, -1, -1, 1};
unsigned seed = chrono::steady_clock::now().time_since_epoch().count();
mt19937 rng(seed);
uniform_int_distribution<int> dist(1, 1e6);
template <typename T>
void dbg(T x) {
  cerr << x << '\n';
}
template <typename T, typename... A>
void dbg(T x, A... y) {
  cerr << x << ", ";
  dbg(y...);
}
template <typename T>
void amax(T &a, T b) {
  if (a < b) a = b;
}
template <typename T>
void amin(T &a, T b) {
  if (a > b) a = b;
}
template <typename T>
bool INR(T a, T b, T c) {
  return b <= a && a <= c;
}
void pmod(ll &a, ll b) { a = (a + b) % MOD; }
void mmod(ll &a, ll b) { a = (a - b + MOD) % MOD; }
void tmod(ll &a, ll b) { a = (a * b) % MOD; }
void UNI(vec<int> &v) {
  sort(v.begin(), v.end());
  v.resize(unique(v.begin(), v.end()) - v.begin());
}
int getint() {
  int ret;
  cin >> ret;
  return ret;
}
ll getll() {
  ll ret;
  cin >> ret;
  return ret;
}
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll POW(ll a, ll b) {
  ll res = 1;
  do {
    if (b % 2) tmod(res, a);
    tmod(a, a);
  } while (b >>= 1);
  return res;
}
const int MXN = 200000;
const int N = MXN + 10;
void solve() {
  int n, m, p;
  cin >> n >> m >> p;
  vec<int> v(n), g(m);
  for (auto &i : v) cin >> i;
  for (auto &i : g) cin >> i;
  v.emplace_back(0);
  g.emplace_back(0);
  sort(v.begin(), v.end());
  sort(g.begin(), g.end());
  vec<int> dp(m + 1);
  for (int i = 1; i <= (n); ++i) {
    for (int j = (m); j >= (i); --j)
      dp[j] = max(dp[j - 1], abs(v[i] - g[j]) + abs(g[j] - p));
    for (int j = (i); j <= (m - 1); ++j) amin(dp[j + 1], dp[j]);
  }
  cout << dp[m] << '\n';
}
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int T = 1;
  while (T--) {
    solve();
  }
}
