#include <bits/stdc++.h>
using namespace std;
long long int dp[2004][2004];
int main() {
  long long int i, j, n, k, p, a[10005], b[10005];
  scanf("%d %d %d", &n, &k, &p);
  for (i = 0; i <= 2000; i++)
    for (j = 0; j <= 2000; j++) dp[i][j] = INT_MAX;
  for (i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (i = 1; i <= k; i++) scanf("%d", &b[i]);
  sort(a + 1, a + n + 1);
  sort(b + 1, b + k + 1);
  for (i = 0; i <= k; i++) dp[0][i] = 0;
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= k; j++) {
      dp[i][j] = min(max(dp[i - 1][j - 1], abs(a[i] - b[j]) + abs(b[j] - p)),
                     dp[i][j - 1]);
    }
  }
  printf("%d", dp[n][k]);
}
