#include <bits/stdc++.h>
using namespace std;
const int N = 2010;
const long long INFLL = 0x3f3f3f3f3f3f3f3f;
long long dp[N][N], a[N], b[N];
int main() {
  int n, k;
  long long p;
  scanf("%d%d%I64d", &n, &k, &p);
  for (int i = 1; i <= n; i++) scanf("%I64d", &a[i]);
  for (int i = 1; i <= k; i++) scanf("%I64d", &b[i]);
  sort(a + 1, a + 1 + n);
  sort(b + 1, b + 1 + k);
  for (int i = 0; i <= n; i++)
    for (int j = 0; j <= k; j++) dp[i][j] = INFLL;
  for (int i = 0; i <= k; i++) dp[0][i] = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= k; j++) {
      dp[i][j] = min(dp[i][j - 1],
                     max(dp[i - 1][j - 1], abs(a[i] - b[j]) + abs(b[j] - p)));
    }
  }
  printf("%I64d\n", dp[n][k]);
  return 0;
}
