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