#include <bits/stdc++.h>
using namespace std;
const long long Maxn = 2010;
long long F[Maxn][Maxn];
long long A[Maxn], B[Maxn];
long long N, K, P;
int main() {
  scanf("%I64d%I64d", &N, &K);
  scanf("%I64d", &P);
  for (long long i = 1; i <= N; i++) scanf("%I64d", &A[i]);
  for (long long i = 1; i <= K; i++) scanf("%I64d", &B[i]);
  sort(A + 1, A + N + 1);
  sort(B + 1, B + K + 1);
  memset(F, 126, sizeof(F));
  for (long long j = 1; j <= K; j++)
    F[1][j] = abs(A[1] - B[j]) + abs(B[j] - P),
    F[1][j] = min(F[1][j], F[1][j - 1]);
  for (long long i = 2; i <= N; i++) {
    for (long long j = 1; j <= K; j++) {
      F[i][j] =
          min(F[i][j], max(F[i - 1][j - 1], abs(A[i] - B[j]) + abs(B[j] - P)));
      F[i][j] = min(F[i][j], F[i][j - 1]);
    }
  }
  return printf("%I64d\n", F[N][K]), 0;
}
