#include <bits/stdc++.h>
using namespace std;
long long dp[1234][2 * 1234];
long long N, K, P;
long long arr[1234];
long long brr[2 * 1234];
long long fun(long long idx1, long long idx2) {
  if (idx2 <= K && idx1 == N) return 0;
  if (idx2 >= K) return 1e18;
  if (dp[idx1][idx2] != -1) return dp[idx1][idx2];
  long long temp = max(abs(arr[idx1] - brr[idx2]) + abs(brr[idx2] - P),
                       fun(idx1 + 1, idx2 + 1));
  temp = min(temp, fun(idx1, idx2 + 1));
  return dp[idx1][idx2] = temp;
}
int main() {
  cin >> N >> K >> P;
  long long i, j;
  for (i = 0; i < N; i++) cin >> arr[i];
  for (i = 0; i < K; i++) cin >> brr[i];
  sort(arr, arr + N);
  sort(brr, brr + K);
  memset(dp, -1, sizeof dp);
  printf("%lld", fun(0, 0));
  return 0;
}
