#include <bits/stdc++.h>
using namespace std;
int ppos[2005];
int kpos[2005];
pair<int, int> seg[2005];
bool tk[2005];
int main() {
  int n, k, p;
  scanf("%d %d %d", &n, &k, &p);
  for (int i = 0; i < n; i++) scanf("%d", ppos + i);
  for (int i = 0; i < k; i++) scanf("%d", kpos + i);
  int lo = 0;
  int hi = 2000000000;
  int md;
  sort(ppos, ppos + n);
  while (lo <= hi) {
    memset(tk, 0, sizeof(tk));
    md = (0ll + lo + hi) / 2;
    for (int i = 0; i < k; i++) {
      seg[i] = make_pair(kpos[i] - (md - abs(kpos[i] - p)),
                         kpos[i] + (md - abs(kpos[i] - p)));
    }
    sort(seg, seg + k);
    bool ok = true;
    for (int i = 0; i < n; i++) {
      bool bad = true;
      for (int j = 0; j < k; j++) {
        if (tk[j]) continue;
        if (seg[j].first <= ppos[i] && seg[j].second >= ppos[i]) {
          tk[j] = true;
          bad = false;
          break;
        }
      }
      if (bad) ok = false;
    }
    if (ok)
      hi = md - 1;
    else
      lo = md + 1;
  }
  printf("%d\n", lo);
}
