#include <bits/stdc++.h>
using namespace std;
void io() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout.precision(15);
}
int A[1002], B[2002];
int n, k, p;
bool check(int maxval) {
  int i = 1;
  int j = 1;
  for (i = 1; i <= n; i++) {
    bool ok = 0;
    while (j <= k && !ok) {
      int dis = abs(A[i] - B[j]) + abs(B[j] - p);
      if (dis <= maxval) {
        ok = 1;
      }
      j++;
    }
    if (!ok) return 0;
  }
  return 1;
}
int main(int argc, char* argv[]) {
  io();
  cin >> n >> k >> p;
  for (int i = 1; i <= n; i++) {
    cin >> A[i];
  }
  for (int j = 1; j <= k; j++) {
    cin >> B[j];
  }
  sort(A + 1, A + n + 1);
  sort(B + 1, B + k + 1);
  int l = 0;
  int r = 2e9 + 1;
  int mid;
  int ans = r;
  while (l <= r) {
    mid = l + (r - l) / 2;
    if (check(mid)) {
      ans = mid;
      r = mid - 1;
    } else {
      l = mid + 1;
    }
  }
  cout << ans << '\n';
  return 0;
}
