#include <bits/stdc++.h>
using namespace std;
long long n, k, p;
long long a[2000];
long long b[2001];
long long dp[1003][2004];
long long cnt = 0;
long long solve(long long index1, long long index2) {
  if (index1 >= n) {
    return dp[index1][index2] = 0;
  }
  if (index2 >= k) {
    return dp[index1][index2] = LONG_LONG_MAX;
  }
  if (dp[index1][index2] != -1) {
    return dp[index1][index2];
  }
  cnt++;
  if (cnt > 10000000) {
    cout << cnt << "\n";
    exit(0);
  }
  long long ans = LONG_LONG_MAX;
  ans = min(max(solve(index1 + 1, index2 + 1),
                abs(a[index1] - b[index2]) + abs(b[index2] - p)),
            solve(index1, index2 + 1));
  return dp[index1][index2] = ans;
}
int main() {
  scanf("%I64d %I64d %I64d", &n, &k, &p);
  for (long long i = 0; i < n; i++) {
    scanf("%I64d", &a[i]);
  }
  for (long long i = 0; i < k; i++) {
    scanf("%I64d", &b[i]);
  }
  sort(a, a + n);
  sort(b, b + k);
  memset(dp, -1, sizeof dp);
  cout << solve(0, 0);
}
