#include <bits/stdc++.h>
using namespace std;
const int N = (int)1e5 + 10;
const int M = (int)1e6 + 10;
const long long LINF = (long long)2e18;
const int INF = (int)1e9 + 7;
const double EPS = (double)1e-9;
const double PI = 3.14159265359;
int n, k, p;
int a[N], b[N];
bool ok(int lim) {
  for (int i = 1, l = 1; i <= n; i++) {
    while (l <= k && abs(a[i] - b[l]) + abs(b[l] - p) > lim) l++;
    if (l <= k && abs(a[i] - b[l]) + abs(b[l] - p) <= lim) {
      ++l;
    } else {
      return false;
    }
  }
  return true;
}
int main() {
  cin >> n >> k >> p;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  for (int i = 1; i <= k; i++) {
    cin >> b[i];
  }
  sort(a + 1, a + n + 1);
  sort(b + 1, b + k + 1);
  int l = 0, r = 2e9 + 10;
  int ans;
  while (l <= r) {
    int mid = (l + 0ll + r) / 2;
    if (ok(mid)) {
      ans = mid;
      r = mid - 1;
    } else {
      l = mid + 1;
    }
  }
  cout << ans;
  return 0;
}
