#include <bits/stdc++.h>
using namespace std;
const long long M = 1e6 + 10, MOD = 1e9 + 7;
long long arr[M], b[M];
long long dp[2002][1001];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, k;
  long long pos;
  cin >> n >> k >> pos;
  for (int i = 0; i < n; i++) cin >> arr[i];
  sort(arr, arr + n);
  for (int i = 0; i < k; i++) cin >> b[i];
  sort(b, b + k);
  for (int i = 0; i <= k; i++)
    for (int j = 0; j <= n; j++) dp[i][j] = 1e17;
  dp[0][0] = 0;
  for (int i = 0; i <= k; i++)
    for (int 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(arr[j] - b[i]) + abs(b[i] - pos)));
      }
    }
  cout << dp[k][n] << endl;
  return 0;
}
