#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e18 + 7;
const int maxN = 2e3 + 5;
int n, k, p;
long long pos[maxN], key[maxN];
long long dp[maxN][maxN];
int res;
long long dist(long long pos, long long key) {
  return abs(pos - key) + abs(key - p);
}
long long solve(int i, int j) {
  if (i == n + 1) return 0;
  if (j == k + 1) return inf;
  if (dp[i][j] != inf) return dp[i][j];
  res++;
  dp[i][j] =
      min(solve(i, j + 1), max(solve(i + 1, j + 1), dist(pos[i], key[j])));
  return dp[i][j];
}
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n >> k >> p;
  for (int i = (1); i <= ((n)); ++i) cin >> pos[i];
  for (int i = (1); i <= ((k)); ++i) cin >> key[i];
  sort(pos + 1, pos + n + 1);
  sort(key + 1, key + k + 1);
  for (int i = (0); i <= ((n + 2) - 1); ++i)
    for (int j = (0); j <= ((k + 2) - 1); ++j) dp[i][j] = inf;
  for (int i = (0); i <= ((k + 2) - 1); ++i) {
    dp[n + 1][i] = 0;
  }
  for (int i = (n); i >= (1); --i) {
    for (int j = (k); j >= (1); --j) {
      dp[i][j] = min(dp[i][j + 1], max(dp[i + 1][j + 1], dist(pos[i], key[j])));
    }
  }
  long long maxim = inf;
  for (int i = (1); i <= ((n)); ++i) maxim = min(maxim, dp[1][i]);
  cout << maxim;
  return 0;
}
