#include <bits/stdc++.h>
using namespace std;
long long a[2005], b[2005], c[2005];
long long dp[2005][2005];
int main() {
  long long n, k, p;
  cin >> n >> k >> p;
  for (long long i = 1; i <= n; i++) cin >> a[i];
  for (long long i = 1; i <= k; i++) cin >> b[i];
  sort(1 + a, 1 + n + a);
  sort(1 + b, 1 + k + b);
  memset(dp, -0xff, sizeof(dp));
  for (long long i = 0; i <= k; i++) dp[0][i] = 0;
  for (long long i = 1; i <= n; i++)
    for (long long j = i; 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)));
  cout << dp[n][k];
}
