#include <bits/stdc++.h>
using namespace std;
int n, k, p;
int a[1010];
int b[2010];
int dp[1010][2010];
int main() {
  cin >> n >> k >> p;
  for (int i = 0; i < n; ++i) cin >> a[i];
  for (int i = 0; i < k; ++i) cin >> b[i];
  sort(a, a + n);
  sort(b, b + k);
  dp[0][0] = 0;
  for (int i = 1; i <= n; ++i) {
    for (int j = i; j <= k; ++j) {
      dp[i][j] =
          max(dp[i - 1][j - 1], (abs(a[i - 1] - b[j - 1]) + abs(b[j - 1] - p)));
      if (i <= j - 1) dp[i][j] = min(dp[i][j], dp[i][j - 1]);
    }
  }
  cout << dp[n][k];
  return 0;
}
