#include <bits/stdc++.h>
using namespace std;
int a[1005], b[2005];
int n, k, P;
bool chk(int x) {
  int p = 1;
  for (int i = 1; i <= n; i++) {
    while (p <= k && abs(a[i] - b[p]) + abs(P - b[p]) > x) ++p;
    if (p > k) return 0;
    ++p;
  }
  return 1;
}
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);
  long long l = 0, r = 2e9;
  long long mid;
  while (l < r) {
    mid = (l + r) / 2;
    if (chk(mid))
      r = mid;
    else
      l = mid + 1;
  }
  cout << r;
  return 0;
}
