#include <bits/stdc++.h>
using namespace std;
int n, k, p, a[1002], b[2002];
int dp[2][1002][2002];
int ans;
int Dist(int i, int j) { return abs(a[i] - b[j]) + abs(b[j] - p); }
void compDp() {
  for (int i = 1; i <= n; ++i)
    for (int j = i; j <= k; ++j) {
      dp[0][i][j] = max(dp[1][i - 1][j - 1], Dist(i, j));
      if (i == j)
        dp[1][i][j] = dp[0][i][j];
      else
        dp[1][i][j] = min(dp[1][i][j - 1], dp[0][i][j]);
    }
  ans = dp[1][n][k];
}
int main() {
  scanf("%d %d %d", &n, &k, &p);
  for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
  for (int i = 1; i <= k; ++i) scanf("%d", &b[i]);
  sort(a + 1, a + n + 1);
  sort(b + 1, b + k + 1);
  compDp();
  printf("%d\n", ans);
  return 0;
}
