#include <bits/stdc++.h>
using namespace std;
void TEST_CASE() {
  long long n, k, p;
  cin >> n >> k >> p;
  long long a[n + 1];
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
  }
  long long b[k + 1];
  for (long long i = 0; i < k; i++) {
    cin >> b[i];
  }
  sort(a, a + n);
  sort(b, b + k);
  long long dp[k + 1][n + 1];
  for (long long i = 0; i <= k; i++) {
    for (long long j = 0; j <= n; j++) {
      dp[i][j] = 1000000000000000000;
    }
  }
  dp[0][0] = 0;
  for (long long i = 0; i < k; i++) {
    for (long long j = 0; j <= n; j++) {
      dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
      if (j < n) {
        dp[i + 1][j + 1] = min(dp[i + 1][j + 1],
                               max(dp[i][j], abs(a[j] - b[i]) + abs(b[i] - p)));
      }
    }
  }
  cout << dp[k][n] << "\n";
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long t = 1;
  while (t--) {
    TEST_CASE();
  }
  return 0;
}
