#include <bits/stdc++.h>
using namespace std;
const int NR = 20000;
const int PR = 1e9 + 7;
int n, k;
long long p;
int a[NR + 1], b[NR + 1];
bool check(long long x) {
  int r = 1;
  for (int i = 1; i <= n; i++) {
    while (r <= k && abs(b[r] - a[i]) + abs(b[r] - p) > x) r++;
    if (r >= k + 1) return false;
    r++;
  }
  return true;
}
int main() {
  scanf("%d%d%lld", &n, &k, &p);
  for (int i = 1; i <= n; i++) scanf("%d", a + i);
  for (int i = 1; i <= k; i++) scanf("%d", b + i);
  sort(a + 1, a + n + 1);
  sort(b + 1, b + k + 1);
  long long l = 0, r = 4e9, ans = 0;
  while (l <= r) {
    long long mid = (l + r) >> 1;
    if (check(mid))
      r = mid - 1, ans = mid;
    else
      l = mid + 1;
  }
  printf("%lld\n", ans);
  return 0;
}
