#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = double;
using pll = pair<ll, ll>;
using vll = vector<ll>;
using vpll = vector<pll>;
using vvll = vector<vll>;
using vi = vector<int>;
struct d_ {
  template <class T>
  d_& operator,(const T& x) {
    cerr << ' ' << x;
    return *this;
  }
  template <class T>
  d_& operator,(const vector<T>& x) {
    for (auto& a : x) cerr << ' ' << a;
    return *this;
  }
} d_t;
ll n, K, p, ppl[1000], key[2000];
int t = (1000 + 2000 + 1) - 1, D[(1000 + 2000 + 1)], P[(1000 + 2000 + 1)], N;
vi G[(1000 + 2000 + 1)];
void add_edge(int u, int v) {
  G[u].push_back(v);
  G[v].push_back(u);
}
bool bfs() {
  queue<int> Q;
  for (decltype(N) i = 0; i < N; ++i)
    if (P[i] == t)
      D[i] = 0, Q.push(i);
    else
      D[i] = (1 << 30);
  D[t] = (1 << 30);
  while (Q.size()) {
    int v = Q.front();
    Q.pop();
    if (D[v] < D[t])
      for (auto w : G[v])
        if (D[P[w]] == (1 << 30)) D[P[w]] = D[v] + 1, Q.push(P[w]);
  }
  return D[t] != (1 << 30);
}
bool dfs(int v) {
  if (v != t) {
    for (auto w : G[v])
      if (D[P[w]] == D[v] + 1 && dfs(P[w])) return P[w] = v, P[v] = w, true;
    D[v] = (1 << 30);
    return false;
  }
  return true;
}
int hopcroft_karp() {
  for (decltype((1000 + 2000 + 1)) i = 0; i < (1000 + 2000 + 1); ++i) P[i] = t;
  int res = 0;
  while (bfs())
    for (decltype(N) i = 0; i < N; ++i)
      if (P[i] == t && dfs(i)) ++res;
  return res;
}
ll dist(ll a, ll b) { return abs(a - b); }
bool can(ll maxt) {
  for (decltype((1000 + 2000 + 1)) i = 0; i < (1000 + 2000 + 1); ++i)
    G[i].clear();
  N = n;
  for (decltype(n) i = 0; i < n; ++i)
    for (decltype(K) j = 0; j < K; ++j)
      if (dist(ppl[i], key[j]) + dist(key[j], p) <= maxt) add_edge(i, n + j);
  auto flow = hopcroft_karp();
  return flow == n;
}
int main() {
  ios::sync_with_stdio(false);
  cout.tie(0);
  cin.tie(0);
  cin >> n >> K >> p;
  for (decltype(n) i = 0; i < n; ++i) cin >> ppl[i];
  for (decltype(K) i = 0; i < K; ++i) cin >> key[i];
  ll l = 0, r = (ll)(2e9 + 7);
  while (l < r) {
    ll m = (l + r) / 2;
    if (can(m))
      r = m;
    else
      l = m + 1;
  }
  cout << l << endl;
  return 0;
}
