#include <bits/stdc++.h>
using namespace std;
const int N = 1001, K = 2001;
const long long INF = 1e18;
int n, k, p, a[N], b[K];
long long dp[N][K];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> k >> p;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i <= k; i++) cin >> b[i];
  sort(a + 1, a + n + 1);
  sort(b + 1, b + k + 1);
  for (int i = 1; i <= n; i++) fill(dp[i], dp[i] + K, INF);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= k; j++) {
      dp[i][j] = min(
          max(dp[i - 1][j - 1], (long long)abs(a[i] - b[j]) + abs(b[j] - p)),
          dp[i][j - 1]);
    }
  cout << dp[n][k];
}
