#include <bits/stdc++.h>
using namespace std;
const int maxn = 2005;
const int mod = 20090717;
const long long INF = 1e15;
const double eps = 1e-6;
int n, k;
long long p;
long long a[maxn];
long long b[maxn];
long long dp[maxn][maxn];
int main() {
  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);
  memset((dp), (0), sizeof(dp));
  for (int i = 1; i <= n; i++)
    for (int j = i; j <= k; j++) {
      if (i == j)
        dp[i][j] = max(dp[i - 1][j - 1], abs(a[i] - b[j]) + abs(b[j] - p));
      else
        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;
}
