#include <bits/stdc++.h>
using namespace std;
const long long maxn = 1010;
long long n, p, k, match[3 * maxn], a[maxn], b[2 * maxn];
bool mark[maxn];
vector<long long> g[maxn];
bool dfs(long long v) {
  if (mark[v]) return false;
  mark[v] = true;
  for (auto u : g[v])
    if (match[u] == -1 || dfs(match[u]))
      return match[v] = u, match[u] = v, true;
  return false;
}
bool f(long long va) {
  for (long long i = 1; i <= n; i++) g[i].clear();
  for (long long i = 1; i <= n; i++)
    for (long long j = 1; j <= k; j++)
      if ((abs(a[i] - b[j]) + abs(b[j] - p)) <= va) g[i].push_back(n + j);
  memset(match, -1, sizeof match);
  while (true) {
    memset(mark, false, sizeof mark);
    bool fnd = false;
    for (long long i = 1; i <= n; i++)
      if (!mark[i] && match[i] == -1) fnd |= dfs(i);
    if (!fnd) break;
  }
  for (long long i = 1; i <= n; i++)
    if (match[i] == -1) return false;
  return true;
}
signed main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> k >> p;
  for (long long i = 1; i <= n; i++) cin >> a[i];
  for (long long j = 1; j <= k; j++) cin >> b[j];
  long long l = -1, r = 2e9;
  while (r - l > 1) {
    long long mid = (r + l) / 2;
    if (f(mid))
      r = mid;
    else
      l = mid;
  }
  cout << r;
  return 0;
}
