#include <bits/stdc++.h>
using namespace std;
long long n, k, p;
vector<long long> a;
vector<long long> b;
long long val(long long num1, long long num2) {
  return (abs(num1 - num2) + abs(num2 - p));
}
bool check(long long num) {
  long long idx_a = 0;
  long long idx_b = 0;
  while (idx_a < n && idx_b < k) {
    long long value = val(a[idx_a], b[idx_b]);
    if (value <= num) idx_a++;
    idx_b++;
  }
  if (idx_a == n) return true;
  return false;
}
int32_t main() {
  cin >> n >> k >> p;
  a.resize(n);
  b.resize(k);
  for (long long i = 0; i < n; ++i) cin >> a[i];
  for (long long j = 0; j < k; ++j) cin >> b[j];
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  long long low = 0;
  long long high = 2e9;
  while (low < high) {
    long long mid = (low + high) / 2;
    if (check(mid))
      high = mid;
    else
      low = mid + 1;
  }
  cout << low;
  return 0;
}
