#include <bits/stdc++.h>
using namespace std;
int n, k, p, arr[1009], arr1[2009], dp[1009][2009], oo = 2e9 + 11;
int bt(int i, int j) {
  if (i == n) return 0;
  if (j == k) return oo;
  if (dp[i][j] != -1) return dp[i][j];
  return dp[i][j] = min(
             bt(i, j + 1),
             max(bt(i + 1, j + 1), abs(arr[i] - arr1[j]) + abs(arr1[j] - p)));
}
int main() {
  memset(dp, -1, sizeof dp);
  cin >> n >> k >> p;
  for (int f = 0; f < n; f++) cin >> arr[f];
  for (int f = 0; f < k; f++) cin >> arr1[f];
  sort(arr, arr + n);
  sort(arr1, arr1 + k);
  cout << bt(0, 0) << endl;
}
