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