#include <bits/stdc++.h>
using namespace std;
long long n, k, p;
vector<long long> pe;
vector<long long> ke;
int main() {
  cin >> n >> k >> p;
  long long a;
  long long mdist = -1;
  for (int i = 0; i < n; i++) {
    cin >> a;
    pe.push_back(a);
    mdist = max(mdist, abs(p - a));
  }
  for (int i = 0; i < k; i++) {
    cin >> a;
    ke.push_back(a);
  }
  sort(pe.begin(), pe.end());
  sort(ke.begin(), ke.end());
  long long lo = mdist, hi = 2e9, mid, found = -1;
  while (lo <= hi) {
    mid = (lo + hi) / 2;
    int i = 0, j = 0;
    long long r, l, dist;
    long long of;
    while (i < k && j < n) {
      if (abs(ke[i] - pe[j]) + abs(ke[i] - p) <= mid) {
        j++;
        i++;
      } else
        i++;
    }
    if (j == n) {
      found = mid;
      hi = mid - 1;
    } else
      lo = mid + 1;
  }
  cout << found << endl;
  return 0;
}
